2

Using jQuery (if it helps), I'd like to create a shortcut key for the letter J, so when someone clicks on the keyboard letter J, it redirects to a webpage.

Is this possible?

Jasper
  • 2,166
  • 4
  • 30
  • 50
mrblah
  • 99,669
  • 140
  • 310
  • 420

3 Answers3

3

The short answer is yes, this is possible. See Jquery Events Keypress

If you want it to be a universal shortcut then simply bind

$(document).keypress(function(event) {
   if (event.which === 106) { window.location = 'your_url'; }
});

Remember to make it very clear to the users that this will happen. There's nothing more off putting to a user than to accidentally trigger a command they didn't know existed.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
2

Based on this page here http://docs.jquery.com/Events/keypress

$().keypress(function (e)
{
   //74 == J
   //106 == j
   if (e.which == 74 || e.which == 106)
    {
         //redirect
    }
});
UnkwnTech
  • 88,102
  • 65
  • 184
  • 229
0

Already asked on SO, read this thread:

Keyboard shortcuts with jQuery

I think, that this answer is what you are looking for (it uses a jQuery plugin):

Keyboard shortcuts with jQuery

Community
  • 1
  • 1
Juraj Blahunka
  • 17,913
  • 6
  • 34
  • 52