Discussion Locked

Javascript: detecting when a link has been clicked

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How can I detect when a link has been clicked but the new page is still in the process of loading? The document.location.href property still understandably displays the current location not the one that's about to load.

I have a page that reloads every 30 seconds in order to access live data. If a user clicks on a link just prior to the page reloading the reload takes precedence over the link click and this is annoying for the users. When the page is about to reload I want to check to see if a link has just been clicked (and therefore a new page is about to load) and, if so, cancel the reload

Any suggestions as to how I can detect this (without having to put and onclick in every link) would be appreciated

2 replies

by john wilker

You could frame the page. move the links to a non refreshing frame and just have the updating data in a different one?

by boologic

add this script block near the bottom of your page:

it should be self-explanatory - attach a handler for onclick the the whole body of the document, then handle if, looking for the A tag.

This discussion is closed to new replies.