Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent scrolling with arrow keys

How can I prevent an HTML page from scrolling when arrow keys are pressed if an iframe inside it is focused?

I'm gettting this error in Chrome

The iframe is focused, I know its focused. The parent scrolls anyway.

like image 252
John Stimac Avatar asked Jul 08 '10 21:07

John Stimac


1 Answers

The following code inside the iframe document will prevent it from scrolling:

document.onkeydown = function(evt) {
    evt = evt || window.event;
    var keyCode = evt.keyCode;
    if (keyCode >= 37 && keyCode <= 40) {
        return false;
    }
};
like image 63
Tim Down Avatar answered Oct 06 '22 08:10

Tim Down