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>
More Related Contents:
- Firefox Web Console Disabled?
- form with no action and where enter does not reload page
- Google’s Imageless Buttons
- Is it possible to make input fields read-only through CSS?
- script links without href=”#”
- button onclick function firing twice
- Fire oninput event with jQuery
- Disable drop paste in HTML input fields? [duplicate]
- Detect if dropdown navigation would go off screen and reposition it
- Iframe inherit from parent
- How to show fullscreen popup window in javascript?
- How to change button text or link text in JavaScript?
- Reading multiple files with Javascript FileReader API one at a time
- copying the value of a form’s file input field to another form’s input field
- Converting sanitised html back to displayable html
- Creating a Clickable Grid in a Web Browser
- Checking if a textbox is empty in Javascript
- Freeze Header until Irrelevant (HTML, CSS and JS)
- How can I fix Highcharts error #13?
- Why do two web pages have different localStorage? How can I fix this?
- Rename Object Key in an array using javascript
- How to apply background-color to a selected option?
- D3 put arc labels in a Pie Chart if there is enough space
- canvas- Cropping images in different shapes
- How to delete an HTML element inside a div with attribute contentEditable?
- converting a javascript string to a html object [duplicate]
- Open link in new window or focus to it if already open
- Use of Template with HTML Custom Elements
- How to encrypt HTML, CSS and JavaScript to prevent copyright infringement [duplicate]
- onclick=”location.href=’link.html'” does not load page in Safari