I'm trying to catch both Ctrl-S and Cmd-S on browsers for cross-OS Compatibility of my web app. I saw a thread about how to do that here: jquery keypress event for cmd+s AND ctrl+s
I have the following snippet in my code:
$(document).keypress(function(event) {
if (event.which == 115 && (event.ctrlKey||event.metaKey)|| (event.which == 19)) {
event.preventDefault();
save();
return false;
}
return true;
});
where save()
is a JavaScript function that will send an AJAX request in the future, but just has alert('Saved!');
for now.
However, although this catches Ctrl-S, it doesn't catch Cmd-S on Chrome, instead just opening the save webpage dialog like usual. I saw that someone else on that page had the same problem, but I didn't see a solution for it.
Thanks in advance!