Menu

Hyperlinks

There are basically two types of hyperlinks provided by go!Johnny: regular links (the TA class, representing a simple a tag) and javascript links (the TJSA class, whose name stands for "JavaScript A").

In both cases, the first parameter represents the resource you are linking to, while the second parameter is the text to be displayed.

<?php
$sf = TA('http://sf.net', 'SourceForge');
$alert = TJSA("alert('Hello!');", 'Click here');
echo $sf . $alert;

output:

<a id="sf" href="http://sf.net" title="SourceForge">
SourceForge
</a>
<a id="alert" href="#" title="Click here" onclick="alert('Hello!');">
Click here
</a>

When using the TJSA class, we recommend putting all your javascript in a separate .js file and include simple function calls in your links. This has the following advantages:

  1. You don't mix two programming languages in the same file.
  2. You get a more organized project.
  3. You will not have problems with nested quotation marks.

Example:

<?php
$action = TJSA("do_something();", 'Click here');
echo $action;

output:

<a id="action" href="#" title="Click here" onclick="do_something();">
Click here
</a>
Posted by panglossa 2013-04-09 Labels: a link hyperlink javascript js TJSA TA url href

Log in to post a comment.