How to turn off the pages on the click on the protein.
-
I'd like to remove the pages when we press the gap. Probed.
preventDefault()
- it didn't work. Then I wanted to fix it so:window.addEventListener('keydown', e => { if (e.keyCode === 32) { document.documentElement.scrollIntoView({ block: 'start' }); } });
But it worked incorrectly, I'd like to know how to fix it.
-
As we have already learned in the comments
preventDefault
In the same processor, after all, successfully stops the scrap and solves the problem:window.addEventListener('keydown', (e) => { if (e.keyCode === 32 && e.target === document.body) { e.preventDefault(); } });
Since the method
preventDefault
prevent(s) the default act enlisted by the browser, it shall be verified in the context of which component it is caused (removal)e.target === document.body
Otherwise, it would prevent the writing of gaps in the text in such elements asinput
♪textarea
♪