Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely DISABLE any MOUSE CLICK

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 
like image 593
Omar Avatar asked Dec 21 '11 20:12

Omar


People also ask

How do I turn off all click events?

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);

How do I turn off the click element?

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.

How do you disable right click using HTML?

Disable right click menu in html page using jquery. JavaScript Code: $(document). bind("contextmenu",function(e){ return false; });


1 Answers

You can add a simple css3 rule in the body or in specific div, use pointer-events: none; property.

like image 65
Leonardo Salles Avatar answered Oct 04 '22 06:10

Leonardo Salles