I am calling e.stopPropagation()
on almost every event that I have for my current application. Is there any way to just stop the propagation for every event wit
To build on Alex's response, in vanilla JS and with a few more events (all the keyboard and click events I could find):
/**
* Disable all user events on the page
*
* @returns {function()} a function to cancel the disabling
*/
const disableAllUserEvents = () => {
const events = ["click", "contextmenu", "dblclick", "mousedown", "mouseenter", "mouseleave", "mousemove",
"mouseover", "mouseout", "mouseup", "keydown", "keypress", "keyup", "blur", "change", "focus", "focusin",
"focusout", "input", "invalid", "reset", "search", "select", "submit", "drag", "dragend", "dragenter",
"dragleave", "dragover", "dragstart", "drop", "copy", "cut", "paste", "mousewheel", "wheel", "touchcancel",
"touchend", "touchmove", "touchstart"];
const handler = event => {
event.stopPropagation();
event.preventDefault();
return false;
};
for (let i = 0, l = events.length; i < l; i++) {
document.addEventListener(events[i], handler, true);
}
return () => {
for (let i = 0, l = events.length; i < l; i++) {
document.removeEventListener(events[i], handler, true);
}
};
};
Edit: Just know that this isn't a secure solution, as those events can be retrieved and canceled: Use Chrome's webkit inspector to remove an event listener