Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent clicking on link while page loading

I have a webpage with some links, and I need to intercept the link-clicking event by jQuery. The task is finished well, but then a problem arises: if the user click a link when javascript doesn't finish loading, it link to another page (which is an error).

I have tried to find a way to disable link-clicking before page loading finish, but the best solution now is that I must add onclick="return false;" into my links, which is not very elegant. Is there any better solution?

Thanks for any help,

like image 685
Hoàng Long Avatar asked Feb 08 '11 03:02

Hoàng Long


People also ask

How do I stop a link from clicking?

Kavitha, try this one. Create a hidden field named clicked and initialize its value to 0. for the first time if you click make the value in the hidden filed as 1. The next time you click check the value of hidden filed, if it is 1 then it is already clicked.

How do I stop a Web page from scrolling to the top when a link is clicked?

To stop a web page from scrolling to the top when a link is clicked that triggers JavaScript, we call preventDefault in the link's click handler. document. getElementById("#ma_link").

How do I stay in the same page after clicking links?

usually href's ar used to transfer the request to another page.. If you want to redirect another page still the existing page remain open use target attribute.. If you dont want to redirect anywhere and still want send a signal while clicking the text, use onclick on the text and not the href.

How do I stop a page from loading in HTML?

Window stop() The stop() method stops window loading. The stop() method is the same as clicking stop in the browser.


1 Answers

You could try using an initialization script:

<script language="javascript">

var loaded = false;

function SetLoaded() { loaded = true; }

window.onload = SetLoaded;

</script>

Then you can add onclick="return loaded;" to your href. Since loaded won't be true until the page loads, it should disable any link with this added.

like image 116
Joel Etherton Avatar answered Oct 02 '22 09:10

Joel Etherton