Saturday, November 30, 2013

You have to go out of your way to get keydown logic to work in JavaScript within Firefox.

$(function() {
   document.onkeydown = function() {
      switch (window.event.keyCode) {
         case 37:
            if (whatever) {

 
 

Per this the blob above had to be refactored into the blob below. What is above accomodated IE 10, Chrome, and Safari. What is below accomodates IE 10, Chrome, Safari, and now Firefox too.

$(function() {
   document.onkeydown = function(event) {
      var key;
      if (window.event) {
         key = window.event.keyCode;
      } else {
         key = event.which;
      }
      switch (key) {
         case 37:
            if (whatever) {

No comments:

Post a Comment