Prevent link clicks on page load

I have a webpage with some links and I need to catch the jQuery click-click event. The task completed well, but then the problem arises: if the user clicks the link when javascript does not finish the download, it links to another page (which is an error).

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

Thanks for any help

+5
source share
4 answers

, : .

<div class="LinkMasker"></div>

.LinkMasker {
    position: absolute;
    z-index: 999;
    width: ...px;
    height: ...px;
}

:

$('.LinkMasker').remove();
0

script:

<script language="javascript">

var loaded = false;

function SetLoaded() { loaded = true; }

window.onload = SetLoaded;

</script>

onclick="return loaded;" href. , .

+5

, R & D . document.readyState "" , .

 if(document.readyState=='complete')
 {
   //// call script or do anything which you want to do.
 }
+3

jQuery hrefs document.ready(). , "#", jQuery.

+1

All Articles