![]() |
Anchor and Javascript - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Anchor and Javascript (/showthread.php?tid=33102) Pages:
1
2
|
Anchor and Javascript - El Forum - 08-16-2010 [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();'"); Code: < a href="http://localhost/index.php/#">< / a > and Code: anchor("[removed]select_all()",img()); Code: < a href="http://localhost/index.php/[removed]select_all();"> < / a > Thank you Anchor and Javascript - El Forum - 08-16-2010 [eluser]Clifford James[/eluser] Use Code: <?=anchor('[removed]//', 'Select All', array('onclick' => 'select_all();'))?> [removed] = java-script:// (minus the -) Anchor and Javascript - El Forum - 08-16-2010 [eluser]SDSL[/eluser] [quote author="Clifford James" date="1281961063"]Use Code: <?=anchor('[removed]//', 'Select All', array('onclick' => 'select_all();'))?> [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 Anchor and Javascript - El Forum - 08-16-2010 [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 -). Anchor and Javascript - El Forum - 08-16-2010 [eluser]SDSL[/eluser] Oh, i was having typo into javascript word Thanks Anchor and Javascript - El Forum - 08-18-2010 [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 Anchor and Javascript - El Forum - 08-18-2010 [eluser]Clifford James[/eluser] Code: <?=anchor('java-script://', 'test', array('onclick' => "ajaxpage('add_client.php', 'contentarea');"))?> Remove the - Anchor and Javascript - El Forum - 08-18-2010 [eluser]redlogic[/eluser] [quote author="Clifford James" date="1282157577"] Code: <?=anchor('java-script://', 'test', array('onclick' => "ajaxpage('add_client.php', 'contentarea');"))?> 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. Anchor and Javascript - El Forum - 08-18-2010 [eluser]Clifford James[/eluser] Make sure you have loaded the url helper: Code: $this->load->helper('url'); You can try this: Code: <?php echo anchor('java-script://', 'test', array('onclick' => "ajaxpage('add_client.php', 'contentarea');")); ?> Remove the - Anchor and Javascript - El Forum - 08-18-2010 [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: <?php echo anchor('page.html', 'Some Page', jslink("ajax('page.html')")) ?> jslink() simply creates an attribute of alt="java-script:{$param}" Code: <?php function jslink($item) {return "alt=\"java-script:{$item}\"";} ?> 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. |