Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to detect when a link is clicked

Reply
Thread Tools

How to detect when a link is clicked

 
 
Mat
Guest
Posts: n/a
 
      08-26-2003
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. Whe 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
 
Reply With Quote
 
 
 
 
Grant Wagner
Guest
Posts: n/a
 
      08-26-2003
Mat wrote:

> 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. Whe 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


You have to put it on each an every link, but if the links don't currently
have onclick events, it isn't that big a deal:

<body onload="window.reloadTimer =
setTimeout('window.location.reload(true);', 30000);setOnClick(onClick);">
<script type="text/javascript">
function onClick() {
if (window.reloadTimer != null) {
clearTimeout(window.reloadTimer);
}
return true;
}
function setOnClick(f) {
// to minimize page size, rather than defining separate onmouseout events
for
// every link, any link without a locally defined onmouseout event is set
here

function __setOnClick(dl, f) {
if (dl) {
for (var i = 0; i < dl.length; i++) {
if (dl[i].onclick == null) {
dl[i].onclick = f;
}
}
}
} // __setOnClick()


__setOnClick(document.links, f);

if (document.layers) {
var dl = document.layers;
for (var i = 0; i < dl.length; i++) {
if (dl[i] && dl[i].document) {
__setOnClick(dl[i].document.links, f);
}
}
}
} // setOnClick()
</script>
</body>

The whole document.layers bit is to support Netscape 4. I just realized it
should be a recursive call, since you can nest layers within layers, but I
never do that so I didn't write it that way. If you don't need to support
Netscape 4, or don't ever use layers in Netscape 4, you could remove that
bit.

--
| Grant Wagner <(E-Mail Removed)>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
in page_load detect what button was clicked thomasamillergoogle@yahoo.com ASP .Net 9 08-20-2009 05:16 AM
Calendar: detect when selected day is clicked Ben Amada ASP .Net 1 01-03-2005 09:20 AM
How to detect when a dynamically added control is clicked who be dat? ASP .Net 7 07-13-2004 01:21 PM
Detect which button was clicked? =?Utf-8?B?RGF2ZQ==?= ASP .Net 3 02-26-2004 07:31 PM



Advertisments