disable all href/links when user click a link

L

Lee

KS said:
Any workaround to this? This is a seriuos web app so I want the solution
where i disable ALL links on my page so it is not possible to click on any
after the first time.

One approach would to ensure that clicking any link immediately loads
an intermediate page that doesn't have anything to click on.

Here's an example that builds that intermediate page on the fly.
This has the side-effect of not allowing some browsers to go BACK
to the page with the links:


<html>
<head>
<script type="text/javascript">
function disableOtherLinks(URL){
globalHtml="<html><body>Please Wait<script type=\"text/javascript\">"
+"location=\""+URL+"\";<\/script></body></html>";
location="javascript:window.globalHtml";
}
</script>
</head>
<body>
<a href="http://www.google.com"
onclick="disableOtherLinks('http://www.google.com');return false">Google</a>
<a href="http://www.yahoo.com"
onclick="disableOtherLinks('http://www.yahoo.com');return false">Yahoo</a>
</body>
</html>
 
K

KS

Im trying to prevent the user from clicking any other links on my page when
the user have selected/clicked a href once.
Sometimes it takes a while before the next page loads so some user will try
clicking other links or the same link.
I can prevent this when i use buttons by calling onclick and in a javascript
getElementsByTagName("input") and then check the type to be type of "button"
or "submit" which i then disable. It works.
This also works for href html tags by calling onclick and in a javascript
remove all href, BUT it also stops everything, even the request that is
about to happen.
If i use disable getElementsByTagName("a") on href like with buttons it does
not get unclickable just get a grey color but you can click on it.

Any workaround to this? This is a seriuos web app so I want the solution
where i disable ALL links on my page so it is not possible to click on any
after the first time.
All the links is NOT in a form only links using <a href="gosomeplace"> click
this link</a> .
 
K

KS

Good idea if I wanted to display the message over the hole page, but I think
it is a bit extreme and will be the last choice if nothing else solves this
problem. There must be someway to disable everything without changing the
look of the page.
If youre solution could write out the text but without the href on it i
would be pleased.
Something like this before onclick:

www.google.com
www.onjava.com
www.javascript.com

and after click , just as above, but then as plain text as if the text was
writen between <td> ...</td> but without the <a href"blabla"> </a>


This javascript does the job, but stop the request which is made when i
click on the link the first time. I would be using onclick to call the
javascript.

function disablehref(){

var input = document.getElementsByTagName("a");

var count = input.length;


for(var i =0; i < count; i++){

document.getElementsByTagName("a").disabled = true;// Does not disable
the link it just gives it a grey color, but works with buttons

document.getElementsByTagName("a").removeAttribute("href"); //OBS this
works but also stops the request and the next page does not get loaded, just
hangs in the first page

document.getElementsByTagName("a").style.cursor=wait';// just to give the
mousepointer the wait symbol instead of the hand

}


return true;


}




Lee said:
KS said:


One approach would to ensure that clicking any link immediately loads
an intermediate page that doesn't have anything to click on.

Here's an example that builds that intermediate page on the fly.
This has the side-effect of not allowing some browsers to go BACK
to the page with the links:


<html>
<head>
<script type="text/javascript">
function disableOtherLinks(URL){
globalHtml="<html><body>Please Wait<script type=\"text/javascript\">"
+"location=\""+URL+"\";<\/script></body></html>";
location="javascript:window.globalHtml";
}
</script>
</head>
<body>
<a href="http://www.google.com"
onclick="disableOtherLinks('http://www.google.com');return
 
V

VK

1st solution is to work via

attachEvent / detachEvent with cancelBubble (Explorer)
addEventListener / removeEventListener with useCapture (Netscape)

"a seriuos web app" - so let it be a serious solution :)

But I would propose much easier 2nd solution. Just make a top level event
listener (window or document) and a hidden div at the bottom of the page

If this listener gets onclick event and its source is a link, it resizes the
div to the size of the screen and makes it visible with some good z-index
(1000 would go for all situations). So effectively you cover all screen with
a transparent glass - you can see, but you cannot touch.
If you also make this div to respond on click events (say show an alert
"Your request is processing, please don't ruch us!" :) - that would be
totally super.
 
L

Lee

KS said:
Good idea if I wanted to display the message over the hole page, but I think
it is a bit extreme and will be the last choice if nothing else solves this
problem. There must be someway to disable everything without changing the
look of the page.

Maybe I'm misunderstanding the situation.
Once the person has clicked on a link, why do they care
if the look of the page changes?
If your page takes long enough to load that they would
get bored looking at a "Please wait" sort of message,
maybe you should be concentrating on speeding up the response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top