Javascript & HREF tricks?
Are there any javascript tricks you play so that whenever someone clicks on a link for a page (a page you own), instead of going directly to the HREF it’ll call a function? Kinda like a global override for a page?
Are there any javascript tricks you play so that whenever someone clicks on a link for a page (a page you own), instead of going directly to the HREF it’ll call a function? Kinda like a global override for a page?
This entry was posted on Friday, December 9th, 2005 at 6:13 pm and is filed under nerd-ness. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

December 10th, 2005 at 9:30 am
Ummm… yeah. onclick=”foo()”
December 10th, 2005 at 11:22 am
Close… basically what I want is something that would do that automatically for every link on the page.
December 10th, 2005 at 1:03 pm
:%s/<a href/<a onclick=”foo” href/g
;-)
December 10th, 2005 at 1:11 pm
you forgot the ‘i’… ;-)
still, i’m hoping to do it through javascript…
December 10th, 2005 at 4:24 pm
Ok fine. After initialization, walk the DOM tree (depends on browser, or get a library that abstracts away the browser differences). Check the type of each object. If it’s an href, modify it like so:
obj.onClick = sub { alert (”Bill likes meat”); }