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 3401418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:00:49+00:00 2026-05-18T05:00:49+00:00

I have a function in jQuery that does something like the following to allow

  • 0

I have a function in jQuery that does something like the following to allow for sitewide keyboard navigation.

function listenForNavKeys(e) {

  // Alt+1 Navigates home
  if(e.which == 49) {
    window.location.replace(location.protocol + '//' + location.host + '/application/views/home.php');
  }
}

For an example of this in action, go to Facebook and press Alt+2 to navigate to your profile. On the Mac, this must be done with Ctrl+Alt+2. However, when I’m listening for the key 50, for example, this keyCode responds to Cmd+2 as well. This is not the desired behavior, since that’s how many users switch between tabs in browsers. The browser functionality still works, but the page will navigate elsewhere while you navigate to another tab.

So how does a site like Facebook handle this event appropriately? What keyCode should I really be listening for?

  • 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-18T05:00:50+00:00Added an answer on May 18, 2026 at 5:00 am

    Whoops. Figured this out far too quickly on my own. My apologies.

    First, my code above is wrong. I meant // Alt+1 in the code. Second, I should be looking for if(e.altKey && e.which == 49). That will get you the correct Alt+# combo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the story... I have a jQuery function that does something, this function is
I have this jquery function that works, except I need to add something. I
I have the following jquery function that submits to an iframe. The message sent
I have a jquery block that does some ajax stuff like this: $.ajax({ url:
i have the following function in jQuery and javascript that creates a form element:
I have this function in jQuery that gets data from a page with POST,
I have a jQuery function that replaces thumbnails with the main image. This is
I have a function called Colorbox (jQuery plugin) that takes a number of parameters
I want to have a jquery function that will be activated when any checkbox
I have a jQuery function - this is the response that is it is

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.