You can attempt to prevent the default action on as many events as you like. Note that browsers usually allow this, but do have the final say (I vaguley remember some issues with this not always working).
var events = ["keypress","click","submit","focus","blur","tab"];
events.forEach(function(eventName){
window.addEventListener(eventName, function(e){
// this is the list of tags we'd like to prevent events on
// you may wish to remove this early return altogether, as even a div or span
// can cause a form to submit with JavaScript
if (["INPUT","A","FORM","BUTTON"].indexOf(e.tagName) === -1) {
return;
}
// prevent the default action
e.preventDefault();
// stop other JavaScript listeners from firing
e.stopPropagation();
e.stopImediatePropagation();
// if an input is somehow focused, unfocus it
var target = e.target;
setTimeout(function(){
if (target.blur) target.blur();
}, 50);
// true as the third parameter signifies 'use capture' where available;
// this means we get the event as it's going down, before it starts to bubble up
// our propagation prevention will thus also prevent most delegated event handlers
}, true);
});
You cannot solve this with CSS. pointer-events
doesn't allow you to specify which pointer events are okay. For that, you do need JavaScript.