Is it possible to detect whether a particular DOM event has any event handler bound to it (including browser default event handling) - within Firefox's Greasemonkey code (EcmaScript 5.1 strict mode)?
So far I managed to cancel my click event handling when a text is selected, but I would like to cancel my event handling in all following situations where click event triggers a default action:
- selecting text on page
- context menu is displayed (i.e. right click)
- a link is followed (left click on
<a>
) - form elements are manipulated (text box gains focus and cursor starts blinking, radio button is selected, ...)
- some other JavaScript code that handles the event (e.g. pop up help dialog is displayed)
Is there a catch-all mechanism for this or do I need to spell all situations in my code explicitly?
Following code is how I detect that selection happened:
var toggleHighlight = function(){
var oldTargt;
return function(e){
targt = e.target;
sel = window.getSelection();
if (!sel.isCollapsed && sel.containsNode(targt, true)) {
return;
}
...
oldTargt = targt;
}()
document.addEventListener('click', toggleHighlight);
Notes:
- I don't want to STOP propagation with my script, I want to stop MY SCRIPT if the event will be propagated to other handler.
- I'm not interested in JQuery-event-handlers-only solutions if they don't catch default browser event handlers.
- If this feature does not indeed exist, please cite some articles or blogs, not just your own opinion.
- Particular suggestions are welcome, but I'm mainly interested in the existence of a general solution.
Update: acceptable solutions include:
- exhaustive(ish) list of
if
conditions that i need to check for - non-javascript way accessible from a Firefox plugin
- explanation of how Firefox knows that a click on a valid
<a>
element should trigger reloading of new URL + how this logic is not accessible from javascript/plugins