Saturday, 15 June 2013

Can't override ctrl+s in Firefox using jQuery Hotkeys -



Can't override ctrl+s in Firefox using jQuery Hotkeys -

i'm using jquery hotkeys plugin: http://code.google.com/p/js-hotkeys/

here code i'm using:

$(document).bind('keydown', 'ctrl+s', function(event) { alert('saving?'); homecoming false; });

in chrome works fine , ctrl+s default functionality over-ridden, in firefox fires alert , tries save html page.

i know there has someway work, wordpress in firefox let's press ctrl+s save.

any ideas?

seems bug in firefox alert breaks synchronicity of code. delaying alert seems workaround issue:

$(document).bind('keydown', 'ctrl+s', function(event) { settimeout(function() { alert('saving?'); }, 0); homecoming false; });

jsbin

here's test case prove bug claim.

$(document).bind('keydown', 'ctrl+s', function(event) { event.preventdefault(); });

the above (bin) prevent save dialog nicely. if add together alert either before or after it, save dialog will appear nevertheless if event.preventdefault() , event.stopimmediatepropagation() or return false:

$(document).bind('keydown', 'ctrl+s', function(event) { event.preventdefault(); event.stopimmediatepropagation(); alert('saving?'); homecoming false; });

bin

event.preventdefault() on own plenty prevent save dialog if there no alerts, alert possible prevent default action.

jquery jquery-plugins jquery-hotkeys

No comments:

Post a Comment