internet explorer - jQuery hotkeys: prevent IE from running its own shortcuts, like Alt+H -


using jquery hotkeys, try bind shortcuts alt + h, alt + c specific actions in site. event propagation stops (as should) in browsers ie. first of all, possible achieve this? if so, how?

here code sample:

jquery(document).bind('keydown', 'alt+h',      function (event)      {         $this.togglemenu( 'h' );         if(jquery.browser.msie) {             event.cancelbubble = true;         }                     else                     {             event.stoppropagation();         }         return false;      } ); 

in ie, line $this.togglemenu( 'h' ); gets executed, cancelbubble seems have no effect (the browser opens "help" menu)

this weird thing attempt (due browser's built-in hotkeys, etc), i've had luck using onkeyup event.

the problem keydown may sending 1 key @ time. if hit alt it's 1 trigger of keydown, , c second trigger. keypress has probs in environments because modifier keys alt , ctrl don't count keypresses (i think.. can explain better?).

if use keyup can check whether alt being held down while checking key. still working out kinks, try (i verified in win7: ie9 , chrome):

$(window).keyup(function (e) {     // warning: tested en-us keyboard / locale      // check whether alt pressed (and not alt+ctrl, alt+shift, etc)     var key = e.key || string.fromcharcode(e.keycode);     if (e.altkey && !e.ctrlkey && !e.shiftkey && key)     {         // if alt pressed, handle keycode shortcut         var keypressed = key.touppercase(); // normalize input         switch (keypressed)         {             case "c":                 // stuff alt-c                 break;             case "h":                 // stuff alt-h                  break;         }     } }); 

problems/questions:

  • uses jquery, pure js solution not complicated
  • is possible prevent default browser behavior canceling event?
  • will work in browsers other chrome , ie9? (probably ff , safari)
  • if user releases alt key before releasing letter key, doesn't work
  • if user presses letter key before pressing alt key, doesn't work
  • tried using accesskey attributes, sets focus.. wanted click hyperlink and/or fire element's click() event based on alt-x combination.
  • while may acceptable enterprise web application (since locale , browser support narrower focus, , since users typically trained on software), may not acceptable web sites (due large number of browsers in use, localization concerns add complexity, etc)... have think more.

hope helps somebody... feel free bring on constructive criticism feature clients asking when build them web apps. (they used legacy form-driven apps of 80s , 90s , want extensive keyboard support, understandable, when pay it!)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -