Skip to content

Instantly share code, notes, and snippets.

@getify
Created September 30, 2014 11:56
Show Gist options
  • Save getify/a523250a779d12993d99 to your computer and use it in GitHub Desktop.
Save getify/a523250a779d12993d99 to your computer and use it in GitHub Desktop.
hijacking clicks using "capturing phase" event handler
// hijack the next click anywhere
if (document.addEventListener) {
document.addEventListener("click",function handler(evt){
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
document.removeEventListener("click",handler,true);
// now do whatever else in response to the hijacked click
},/*capturing=*/true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment