After the user clicks on...."log in" button, and other events, I made a loading script -to let users know they have to wait (Until ajax replies back).
How can I DISABLE any MOUSE CLICKS (right click, left click, double click, middle click, x click), on div id="doc"
?
I want to add that code to loading.js
HTML
<html> ... <body> <div id="doc"> <div id="content"> ... <input type="button" value="Login" id="login" /> ... </div id="content"> </div id="doc"> </body> </html>
loading.js
function load_bar(x) { if (x==0) { $(document.body).css( {"cursor": "default"} ); $("body").css( {"cursor": "default"} ); $("#loading").css("visibility", "hidden"); //modal window // $("#doc").....ENABLE all clicks (left/right/etc) } else if (x==1) { $(document.body).css( {"cursor": "wait"} ); $("body").css( {"cursor": "wait"} ); $("#loading").css( {"visibility": "visible"} ); //modal window // $("#doc").....DISABLE all clicks (left/right/etc) } else { return alert("Wrong argument!"); } }
jQuery
$(document).ready(function() { //AJAX $("#login").click(function() { load_bar(1); //DISABLE clicks and show load_bar $(":input").attr("disabled", true); $.post( ... function(data) { ... load_bar(0); //ENABLE clicks and hide load_bar ... } //END: if:else }); //END:$.post ... }); //END:ajax }); //END:jQuery
Dynamically disable all clicks on pagelet freezeClic = false; // just modify that variable to disable all clics events document. addEventListener("click", e => { if (freezeClic) { e. stopPropagation(); e. preventDefault(); } }, true);
Conclusion. To disable clicking inside a div with CSS or JavaScript, we can set the pointer-events CSS property to none . Also, we can add a click event listener to the div and then call event. preventDefault inside.
Disable right click menu in html page using jquery. JavaScript Code: $(document). bind("contextmenu",function(e){ return false; });
You can add a simple css3 rule in the body or in specific div, use pointer-events: none;
property.
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