Try checking if target
is the body:
window.addEventListener('keydown', function(e) {
if(e.keyCode == 32 && e.target == document.body) {
e.preventDefault();
}
});
body { height: 100000px; }
<input />
<textarea></textarea>
Demo
Try checking if target
is the body:
window.addEventListener('keydown', function(e) {
if(e.keyCode == 32 && e.target == document.body) {
e.preventDefault();
}
});
body { height: 100000px; }
<input />
<textarea></textarea>
Demo