First of all, here is a list of event types that are defined by the W3C standards. (This list is based on the onevent attributes defined in the HTML5 standard. I assume that there are dozens of other event types, but this list is long enough as it is.)
- abort
- afterprint
- beforeprint
- beforeunload
- blur
- canplay
- canplaythrough
- change
- click
- contextmenu
- copy
- cuechange
- cut
- dblclick
- DOMContentLoaded
- drag
- dragend
- dragenter
- dragleave
- dragover
- dragstart
- drop
- durationchange
- emptied
- ended
- error
- focus
- focusin
- focusout
- formchange
- forminput
- hashchange
- input
- invalid
- keydown
- keypress
- keyup
- load
- loadeddata
- loadedmetadata
- loadstart
- message
- mousedown
- mouseenter
- mouseleave
- mousemove
- mouseout
- mouseover
- mouseup
- mousewheel
- offline
- online
- pagehide
- pageshow
- paste
- pause
- play
- playing
- popstate
- progress
- ratechange
- readystatechange
- redo
- reset
- resize
- scroll
- seeked
- seeking
- select
- show
- stalled
- storage
- submit
- suspend
- timeupdate
- undo
- unload
- volumechange
- waiting
Now, is it possible to define a global event handler that is called when any event originally occurs on any element on the page? (In this case, I don't want to count those events that occurred on elements because they bubbled up from a descendant element - that's why I wrote "originally occurs".)
If that is not possible, is it at least possible to define an event handler that is called when any event bubbles up to the root of the DOM tree (which is either the document
object or the window
object - both should work)? (I know that it's possible to stop bubbling programmatically, but I would use this event handler on a page that has no other handlers defined on any other elements.) (Also, I believe some events don't bubble up, but let's ignore these cases for the sake of this argument.)
I know that I can do this (using jQuery):
$(document).bind('abort afterprint beforeprint beforeunload etc.', function() {
// handle event
});
but that would be a rather undesirable solution for me.
btw I don't need a cross-browser solution. If it works in just one browser, I'm fine.
Also, Firebug is able to log events, but I would like to be able to catch the event programmatically (via JavaScript) rather then having them simply logged in the console.