Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding Browser's Keyboard Shortcuts

Tags:

javascript

I'd like to add support for keyboard shortcuts to a couple of pages in my web application by intercepting the keypress event handler of the document object, not the accesskey attribute.

The problem is that every browser has its own keyboard combinations, so it's impossible to come up with a set of keyboard combinations that work on all web browsers and yet consistent.(e.g. It'd be silly if the shortcut for save was Ctrl + Shift + S while one for delete was Alt + D.)

So I figured it would be just simpler to override browser shortcuts altogether in a couple of pages with mine.

All downside aside, is it possible? If so, how do you do it?

like image 606
Tom Tucker Avatar asked Sep 09 '10 22:09

Tom Tucker


1 Answers

onkeydown = function(e){   if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)){     e.preventDefault();     //your saving code   } } 
like image 152
antimatter15 Avatar answered Oct 09 '22 15:10

antimatter15