prevent scroll page with arrow keys
I'm trying to show the game inside a lightbox. The problem is when pressed arrow keys to play the game, the parent page scrolls up and down. How can i block this event?
I tested this code:
document.onkeydown = function(evt) {
evt = evt || window.event;
var keyCode = evt.keyCode;
if (keyCode >= 37 && keyCode <= 40) {
evt.preventDefault();
return false;
}
};
Works in firefox and IE but not in chrome.
I tested this code:
document.onkeydown = function(evt) {
evt = evt || window.event;
var keyCode = evt.keyCode;
if (keyCode >= 37 && keyCode <= 40) {
evt.preventDefault();
return false;
}
};
Works in firefox and IE but not in chrome.
Comments