Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:59:03+00:00 2026-05-27T09:59:03+00:00

This is a catch 22 I can’t really figure out how to resolve. Take

  • 0

This is a catch 22 I can’t really figure out how to resolve. Take this HTML5 game we host:

http://www.scirra.com/arcade/action/93/8-bits-runner – Warning has sound!

The page is hosted on scirra.com but the game is in an iframe on static1.scirra.net for security reasons.

Now if you press left and right, up or down when you are playing the game the entire window scrolls up and down, left and right. The prevent default seems to work OK when the game isn’t focused. We want to prevent this default action when playing the game of course! So we use the code:

    var ar = new Array(32, 33, 34, 35, 36, 37, 38, 39, 40, 44);
    $(document).keydown(function (e) {            
        var key = e.which;
        if ($.inArray(key, ar) > -1) {
                e.preventDefault();
                return false;
        }
        return true;
    });

We put this on the parent page and the iframe page. When the iframe has focus left and right seem to be blocked, but not up and down.

Can anyone help us work out how to stop the page scrolling, AND still allow people to type comments in the comment box below the game? If you block space bar it stops people being able to add spaces in their text!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:59:04+00:00Added an answer on May 27, 2026 at 9:59 am

    I may not fully understand the problem, but it seems like you want:

    1. up, down, space, etc. to go only to the game window only when that has focus.
    2. up, down, space, etc. to go to the comment box when that has focus.
    3. up, down, space, etc. to go to the main window when that has focus.

    Number #2 and #3 are what happen automatically if you do nothing. So basically you want #1. I don’t see why you need any code on the main window.

    This works in Chrome, Opera, FF, IE9, IE8, IE7 in my tests.

    Main Window

    Demo: http://jsfiddle.net/ThinkingStiff/Dp5vK/

    HTML:

    <iframe id="game" src="http://jsfiddle.net/ThinkingStiff/dtmxy/show/"></iframe>
    <textarea id="comment-box"></textarea>
    

    CSS:

    #game {
        border: 1px solid red;
        display: block;
        height: 100px;
        width: 200px;
    }
    
    #comment-box {
        height: 100px;
        width: 200px;
    }
    
    body {
        height: 1000px;
        width: 1000px;
    }
    

    Game Window (iframe)

    Demo: http://jsfiddle.net/ThinkingStiff/dtmxy/

    Script:

    $( document ).bind( 'keydown', function ( event ) {
    
        var keys = [32, 33, 34, 35, 36, 37, 38, 39, 40, 44];
    
        if( keys.indexOf( event.which ) > -1 ) {
    
            event.preventDefault();
            event.stopPropagation();
    
        };
    
    } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I catch this TypeInitializationException ? Don't really care if it is C#
This article on MSDN states that you can use as many try catch blocks
I've registered 3 domains, all for the same site. I've done this to catch
I'm bored with surrounding code with try catch like this.. try { //some boring
Is this regular expression enough to catch all cross site scripting attempts when embedding
This is a self-explanatory question: Why does this thing bubble into my try catch's
Why is this code correct: try { } catch(ArrayOutOfBoundsException e) {} and this wrong:
I am using Delphi TApplication.OnException Event to catch unhandled exceptions This works well but
I've have searched on this and it seems to be a catch all, unfortunately
Is it better to do this: try { ... } catch (Exception ex) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.