views:

60

answers:

2

I'm making a simple UI demo and need to assign the 0 on the keypad (or perhaps the ESC key in the future) to the back function of a browser.

I've found a few keypress tutorials that deal with specific requirements but none that seems to fit mine. Any advice would be appreciated!

+1  A: 

I may not have the right selector...someone please fix if I have that bit wrong (might be $(window)). Otherwise, you should do something like this.

$(document.documentElement).keyup(function (event) {
   if (event.keyCode == 30) {
     history.back();
   }
});
JasCav
+1  A: 
$('body').keypress(function(event) {
    if(event.which == "48" || event.which == "96"){
     alert('number 0 has been pressed');
    }
});​
From.ME.to.YOU