Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  71] [ 3]  / answers: 1 / hits: 17146  / 12 Years ago, mon, january 28, 2013, 12:00:00

I was trying to implement the CTRL+S feature for a browser based application. I made a search and came across two scripts in the following to questions


Best cross-browser method to capture CTRL+S with JQuery?

Ctrl+S preventDefault in Chrome


However, when I tried to implement it, it worked but, I still get the default browser save dialog box/window.


My Code:For shortcut.js:


 shortcut.add("Ctrl+S",function() {
alert("Hi there!");
},
{
'type':'keydown',
'propagate':false,
'target':document
});

jQuery hotkeys.js:


$(document).bind('keydown', 'ctrl+s', function(e) {
e.preventDefault();
alert('Ctrl+S');
return false;
});

I believe e.preventDefault(); should do the trick, but for some reason it doesn't work. Where am I going wrong.Sorry if it is simple, still learning jJvascript.


More From » jquery

 Answers
3

This is to just add a different implementation to the question used by me.
Adapted from a SO answer.Also,works for MAC



 document.addEventListener(keydown, function(e) {
if (e.keyCode == 83 && (navigator.platform.match(Mac) ? e.metaKey : e.ctrlKey)) {
e.preventDefault();
//your implementation or function calls
}
}, false);

[#80577] Saturday, January 26, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;