Click to See Complete Forum and Search --> : Detecting when a link has been clicked


mat_guthrie
08-26-2003, 06:54 AM
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 displays the current location (understandably) 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

Charles
08-26-2003, 12:27 PM
Each link has an "onclick" handler. Use those to call "clearTimeout()".

pyro
08-26-2003, 12:29 PM
...and you can use a loop to loop through all the links in the document.

Charles
08-26-2003, 12:31 PM
...once the document, or at least the part with the links, is fully loaded.

AdamBrill
08-26-2003, 12:36 PM
Yes... To do that, you can use this. Put this in the head:<script type="text/javascript">
function setup(){
for(x=0; x<document.links.length; x++){
document.links[x].onclick=function(){
clearInterval("whatever");
return false;
}
}
}
</script>Then add setup into the body's onload. Like this:

<body onload="setup();">

pyro
08-26-2003, 12:36 PM
lol... :D