Welcome Guest, Not a member yet? Register   Sign In
Anchor and Javascript
#1

[eluser]SDSL[/eluser]
How would you add javascript action to your anchor helper?
since the anchor helper insert the full url path in-front of the javascript it becomes useless
For example
Code:
anchor("#",img(), "onclick='select_all();'");
becomes
Code:
< a href="http://localhost/index.php/#">< / a >

and
Code:
anchor("[removed]select_all()",img());
becomes
Code:
< a  href="http://localhost/index.php/[removed]select_all();"> < / a >

Thank you
#2

[eluser]Clifford James[/eluser]
Use

Code:
&lt;?=anchor('[removed]//', 'Select All', array('onclick' => 'select_all();'))?&gt;

[removed] = java-script:// (minus the -)
#3

[eluser]SDSL[/eluser]
[quote author="Clifford James" date="1281961063"]Use

Code:
&lt;?=anchor('[removed]//', 'Select All', array('onclick' => 'select_all();'))?&gt;

[removed] = java-script:// (minus the -)[/quote]

doesn't work on firefox because firefox think it's new protocol, haven't tried other browsers

there should be other way to not include the full URL within the href
#4

[eluser]Clifford James[/eluser]
[quote author="SDSL" date="1281961421"]doesn't work on firefox because firefox think it's new protocol, haven't tried other browsers

there should be other way to not include the full URL within the href[/quote]

It does work for me in FireFox. Make sure you use java-script:// (remove the -).
#5

[eluser]SDSL[/eluser]
Oh, i was having typo into javascript word

Thanks
#6

[eluser]redlogic[/eluser]
hi there,

i'm having trouble with this as well, only i need to wrap the url in a js function. here's what i need to end up with:

Code:
<a href="[removed]ajaxpage('add_client.php', 'contentarea');">test</a>

thanks
#7

[eluser]Clifford James[/eluser]
Code:
&lt;?=anchor('java-script://', 'test', array('onclick' => "ajaxpage('add_client.php', 'contentarea');"))?&gt;

Remove the -
#8

[eluser]redlogic[/eluser]
[quote author="Clifford James" date="1282157577"]
Code:
&lt;?=anchor('java-script://', 'test', array('onclick' => "ajaxpage('add_client.php', 'contentarea');"))?&gt;

Remove the -[/quote]

Hi Clifford,

Thanks for the quick response! I've tried the above, but it isn't outputting any html (i removed the -).Just an empty space where the link should be.
#9

[eluser]Clifford James[/eluser]
Make sure you have loaded the url helper:
Code:
$this->load->helper('url');

You can try this:
Code:
&lt;?php echo anchor('java-script://', 'test', array('onclick' => "ajaxpage('add_client.php', 'contentarea');")); ?&gt;

Remove the -
#10

[eluser]Kindari[/eluser]
I do things a little differently, so that all my links are backwards compatible. I made an entire version of my site that works without javascript on.

For all my links, I do:

Code:
&lt;?php echo anchor('page.html', 'Some Page', jslink("ajax('page.html')")) ?&gt;

jslink() simply creates an attribute of alt="java-script:{$param}"

Code:
&lt;?php function jslink($item) {return "alt=\"java-script:{$item}\"";} ?&gt;
(obviously remove hypen from the function call.)
Finally to get all of these links to work when javascript is enabled.

Code:
$("a[alt]").attr("href",function(index, Element) {  return $(this).attr('alt');  });

(using jquery).


Now note, alt is not officially a supported attribute for the a tag, so validation will fail. But I dont really like the onclick methods, I just thought Id share to give you other ideas of how to accomplish.




Theme © iAndrew 2016 - Forum software by © MyBB