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

  • Home
  • SEARCH
  • 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 632539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:05:16+00:00 2026-05-13T20:05:16+00:00

I have a problem that I’m not even sure what to search for in

  • 0

I have a problem that I’m not even sure what to search for in order to fix. When I press the spacebar my entire page moves up (scrolls down): I don’t want this to happen. My body tag is styled to overflow:hidden, if that has anything to do with it, so the page won’t have any scrollbars. I’m usually pretty good at executing the preliminary troubleshooting techniques but in this case I don’t even know where to start. How can I stop this behaviour?

Additional information: I am using jQuery 1.4.2

  • 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-13T20:05:16+00:00Added an answer on May 13, 2026 at 8:05 pm

    This default scrolling behavior comes from the keydown event. In order to prevent it, you must handle the keydown event and prevent the default behavior, either by returning false from the event handler or calling event.preventDefault().

    As a rule of thumb, think carefully before you prevent default behavior like spacebar scrolling. I use it all the time and I get extremely annoyed when it doesn’t work in a page.

    But if you want to eat the key…

    window.onkeydown = function(e) {
        return e.keyCode !== 32;
    };
    

    According to the MDN web docs for KeyboardEvent#keyCode, keyCode is a deprecated property. Although it still works in most browsers, you are encouraged to use #KeyboardEvent #key (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) going forward, which is a more standardized string representation of a key. The key value for spacebar is literally the input value: " " (single space string). So if you wanted to be very careful to support all browsers, you could write:

    window.onkeydown = function(e) {
        return e.keyCode !== 32 && e.key !== " ";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I am not sure of the best way to
I have a problem that I have not seen addressed in this particular way
I have a problem that I have not managed to solve. I developed a
I have a problem that I think is caused by the wm_keyup message not
I have problem that says The specified named connection is either not found in
I have this problem that I cannot fix. From my @Controller , i can
I have problem that on server include() function does not want to work and
I have problem that seems to be rather trivial but I was not able
I have a problem that is not uncommon when building a plug-in architecture. Assembly
I am new to ObC and have a problem that i just cant fix.

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.