nezgerland
nezgerland

Reputation: 369

How to determine + key down?

Using jQuery, how do I determine that user has pressed '+'. I know that by matching keycode in the keydown event is the way to go, but that is apparently not cross platform. Since, the keycodes vary in Linux OS. Matching to charcode is also not an option because it is not cross browser. IE, of course, does not support charcode.

Does anyone know a cross platform solution to do this? Google+ has apparently been able to achieve this.

Upvotes: 0

Views: 78

Answers (1)

genesis
genesis

Reputation: 50982

$("#element").keyup(function(e){
   if (e.keyCode == 61 || e.keyCode == 107){ // 61 for windows, 107 for mac
      //do stuff
   }
}

or, if you feel this isn't reliable, use

if ($.firefox){
   var keycode = ..;
}

if ($.opera){
    var keycode = ..;
}
// and more

where you have to change .. with certain keycode working in that browser

Upvotes: 2

Related Questions