Switch keyboard shortcuts in firefox and chrome

I have a script that should open a section of a webpage and save the changes to Ctrl + n and Ctrl + s. I'm sure it works in IE, but it does not work in firefox and chrome, Any ideas?

My ride function.

function prevent(e) { try{e.stopPropagation();}catch(ex){} try{e.preventDefault()}catch(ex){} try{if (e.preventDefault) e.preventDefault(); else { e.cancelBubble = true; e.returnValue = false; e.keyCode = 0; }} catch(ex){} } 
+4
javascript html firefox google-chrome
source share
1 answer

I saw the same problem. Some browsers will not allow you to fix certain shortcuts. Have a look at this fooobar.com/questions/102390 / ...

Some key combinations are specified in Chrome 4, but not in Chrome 3. See here: https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-bugs/Ntc1byZXHfU

Here is the Javascript:

 $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 84) { console.log("Hey! Ctrl+T event captured!"); event.preventDefault(); } if(event.ctrlKey && event.keyCode == 83) { console.log("Hey! Ctrl+S event captured!"); event.preventDefault(); } }); 

I used this many times and it worked a lot.

Here is another rescource you can take a look at: http://unixpapa.com/js/key.html

Without jQuery:

 onkeydown = function(e){ if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)){ e.preventDefault(); //your saving code } } 

Here is the JSFIDDLE work.

+8
source share

All Articles