Welcome Guest, Not a member yet? Register   Sign In
Anchor and Javascript
#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:
<?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}\"";} ?>
(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.


Messages In This Thread
Anchor and Javascript - by El Forum - 08-16-2010, 01:14 AM
Anchor and Javascript - by El Forum - 08-16-2010, 01:17 AM
Anchor and Javascript - by El Forum - 08-16-2010, 01:23 AM
Anchor and Javascript - by El Forum - 08-16-2010, 01:29 AM
Anchor and Javascript - by El Forum - 08-16-2010, 01:36 AM
Anchor and Javascript - by El Forum - 08-18-2010, 07:48 AM
Anchor and Javascript - by El Forum - 08-18-2010, 07:52 AM
Anchor and Javascript - by El Forum - 08-18-2010, 08:13 AM
Anchor and Javascript - by El Forum - 08-18-2010, 08:16 AM
Anchor and Javascript - by El Forum - 08-18-2010, 11:41 AM
Anchor and Javascript - by El Forum - 08-19-2010, 04:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB