I see this is very popular question, but i still cannot find right solution.
I'm trying to call function (save) on Ctrl+s pressed inside my textarea. I found that Chrome or IE needs "keydown" and FireFox needs "keypress".
Actually, Firefox registers "keydown" - calls my "alert" but don't prevent browser "Save As" dialog.
I tried to put both events, - then FireFox prevents Save As dialog, but calls my Alert twice.
Here's code:
$("#mytextarea").on("keypress keydown",function(e) {
if ((e.which == '115' || e.which == '83' ) && (e.ctrlKey || e.metaKey)) {
e.preventDefault();
alert("Ctrl-s pressed");
return false;
}
return true;
});
JS fiddle - try to open with FF
Does anyone have real crossbrowser solution?