I use jQuery-hotkeys
And the following code:
$(document).bind('keydown', 'ctrl+s', function(){$('#save').click()});
but I cannot disable the browser's default behavior. How do I disable it?
It looks like you return false from your handler to disable "bubbling up" the event. So:
$(document).bind('keydown', 'ctrl+s', function(){$('#save').click(); return false;});
... but it may be browser specific. From your link:
Firefox is the most liberal one in the manner of letting you capture all short-cuts even those that are built-in in the browser such as Ctrl-t for new tab, or Ctrl-a for selecting all text. You can always bubble them up to the browser by returning true in your handler.
Others, (IE) either let you handle built-in short-cuts, but will add their functionality after your code has executed. Or (Opera/Safari) will not pass those events to the DOM at all.
So, if you bind Ctrl-Q or Alt-F4 and your Safari/Opera window is closed don't be surprised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With