Intercepting static and dynamic links using javascript

I'm currently developing an ajax application and I'm looking for a feature that lets me intercept all static and dynamic links using javascript. The links look like these:

<a href="link1/">link 1</a>
<a href="link2/">link 2</a>
etc.

I then want the browser to redirect to: current.page/#link1/ rather than current.page/link1/. I'm using jQuery, so the live() function is an option, however using that as a solution just seems rather sluggish to me(am I hysterical?). If there is a way to intercept ALL links on a page, maybe through detecting a change in the address, that would greatly help. I've tried a few plugins for jQuery (jQuery address & SWFaddress) but they only seem to have event handlers that respond to changes in anchor tags in the address. Any ideas?

thanks for your time

Answers


Don't worry to much about performance unless you have to. Often the elegant solution is also the right one.

I would use jQuerys live function, bind to the click event and rewrite the link as it is being clicked on.

Hope this helps, Egil.


What the live function does is it binds an event handler to the document, which catches all click events and then detects all clicks that match the selector, in your case the link elements. This is the most efficient way of catching all link clicks.


Need Your Help

Add only new records in MySQL via script

mysql sql perl optimization query-optimization

I have a large database which I am trying to update via perl. The information to be added comes from a csv file which I do not control (but which is trusted&mdash;it comes from a different part of...

OAuth token Expires Time different between accounts

facebook api oauth

Strange issue, perhaps I'm missing something here.