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?

5 Responses to “Javascript & HREF tricks?”

  1. Tony Says:

    Ummm… yeah. onclick=”foo()”

  2. Bill Says:

    Close… basically what I want is something that would do that automatically for every link on the page.

  3. Tony Says:

    :%s/<a href/<a onclick=”foo” href/g

    ;-)

  4. Bill Says:

    you forgot the ‘i’… ;-)

    still, i’m hoping to do it through javascript…

  5. Tony Says:

    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”); }

Leave a Reply