On my page I have a lot of various elements which respond to click events. There are times when I need to block all clicks based on some global flag. Is there a way I can ma
Yes, use .addEventListener() and set the 3rd option to true. This will bind the listener to the capture phase and execute the function before anything else gets executed.
Here's an example where this will stop all click handlers from executing:
document.addEventListener('click', function(e) {
e.stopPropagation();
}, true);
See it in action here:
http://jsfiddle.net/wLwMh/1/
Using Inject Javascript :
view.loadUrl(
"javascript:(function() {"
+ "document.addEventListener('click', function(e)"
+ "{"
+ "e.stopPropagation();"
+ "}"
+ ", true);"
+ "})()"
);
You could capture all the click events then trigger a custom event where you have your listeners bound after your check
$("#someDiv").bind('awesomeEvent', function() {
//do stuff here
}
$(*).click(function() {
if(canClick) {
$(this).trigger('awesomeEvent');
}
}
EDIT I should mention that using the $(*) selector is not a good idea from a performance standpoint. You should really try and narrow the scope somehow.