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,
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.
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").
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.
Window stop() The stop() method stops window loading. The stop() method is the same as clicking stop in the browser.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With