How to disable parent page scrolling

I have iframe html5 game with arrow keys control. Task is to disable parent page scrolling when arrow keys pressed.

Solution:

Add next code to iframe head block:

<script>
window.addEventListener("keydown", function(e) {
    // space and arrow keys
    if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
        e.preventDefault();
    }
}, false);
</script>

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *




Enter Captcha Here :