473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to detect when a link is clicked

Mat
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
Jul 20 '05 #1
1 13463
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 <gw*****@agricoreunited.com>

* 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
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: selowan | last post by:
Hi, In VB6 Pro SP5, I have a form that contains an MSFlexGrid and a few other textboxes and comboboxes. I am using the technique from MSDN article Q241355, which describes how to tab and edit in...
8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
5
by: Quinn | last post by:
When users clicked a unkown mime type link such as Zip on my website, a "Save/Open/Cancel" dialog box pops up. Is there a way to detect which button users clicked by using ASP? actually I only what...
7
by: who be dat? | last post by:
I need some help here. I'm creating a list on a page where the list is created from a dataset with two tables linked with a datarelation. The first table is a list of groups while the second...
1
by: Ben Amada | last post by:
Hi, I'm using the built-in calendar control. One problem I'm having is that if the user clicks on the day in the calendar which is already the SelectedDate, a postback occurs, but the...
8
by: thomasamillergoogle | last post by:
I am trying to detect what asp.net button was clicked duing the page_load event. I have two asp.net buttons on my page. What is the easiest way to detect this?
2
by: needin4mation | last post by:
Hi, I have two links, one function. Both links are wired via the onclick to the same function. I want to test in the function which link was clicked and code accordingly. How? I have looked...
1
by: Jessica | last post by:
Hi, I'm sorry if this has been asked before. I'm a designer and occasional javascript hacker, not a javascript writer. I cannot believe I have spent over 4 hours searching for this on Google and...
1
by: maminx | last post by:
i want to detect Link in a Tab is activated or clicked from my code. here the situation I have tabs that have link to web pages like example below : <ul id="tabs"> <li><a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.