How to cancel all click events in document in JQuery
How can I cancel all click events in a HTML document?
I have a Webapp where a situation can occur where the user needs to accept
a message before to go on. The idea is that the message appears and when
the user clicks somewhere else the message blinks or tries to catch the
user's attention
This app is intended to be used by administrations using IE 8 and up +
modern browsers, that's why I was hoping for a jquery solution.
At the moment, I tried
$(document).bind('click', function(event){
event.stopImmediatePropagation();
$('.alertbox').effect('shake');
return false;
});
hoping the return false or the event stop propagation would stop the
click, But I found out the event bubbles up from the Dom element to the
document, so the dom element fires the click anyway.
I found a solution in pure JS:
document.addEventListener('click', function(e) {
e.stopPropagation();
}, true);
using true as a third argument will bind the listener to the capture phase
and execute the function before anything else gets executed, but this
doesn't work well in IE.
I don't necessarily need a solution to get a pre-bubble click event in IE
(although this would be nice) If I could find a trick or a workaround, I
could live with it. Any idea?
No comments:
Post a Comment