views:

1883

answers:

1

See title. Since I'm using jQuery, any solution via. that would work too. Ideally, I'd like to know both, though. I already have the arrow keys bound to another function on my page (via. jQuery), but having them cause the page to scroll in addition to that causes me problems.

I may have known this at one time, but I don't remember it anymore. :P

+6  A: 

Adding document level keypress handler does the trick!

var ar=new Array(33,34,35,36,37,38,39,40);

$(document).keypress(function(e){
     var key=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
      //console.log(key);
      //if(key==35 || key == 36 || key == 37 || key == 39)
      if($.inArray(key,ar))
      {
          e.preventDefault();
          return false;
      }
      return true;
});
TheVillageIdiot
Oh neat. Lemme give it a shot...
Daddy Warbox
It handles PgUp(33), PgDn(34), End(35), Home(36), Left(37), Up(38), Right(39), Down(40)
TheVillageIdiot
Yay! Thanks a lot.
Daddy Warbox
really nice code, i like your code very much!
Srikanth