jquery shortcuts not working on IE
Hi I am using jQuery.hotkeys.js plug in for key board shortcut. All other shortcuts are working fine but f1 is not working as expected in IE. On 'f1' keypress it binds the shortcut but is being called more than one time and also it opens help window as well.
the code is like this:
$(document).bind('keydown', 'f1', function (evt) {
evt.preventDefault();
evt.stopPropagation();
alert('some message');
windo开发者_JAVA百科w.event.keyCode = 0;
return false;
});
please give me idea for this.
Thanks
Munish
In Internet Explorer, the F1 key cannot be cancelled from the keydown handler. You can attach to the onhelp
event instead:
window.onhelp = function () {
return false;
}
The firing twice issue is possibly a bug in the plugin code, if it's only occurring in Internet Explorer you can work around it by using the onhelp
event exclusively:
if ("onhelp" in window) // IE
window.onhelp = function() {
alert("some message");
return false;
}
else // Others
$(document).bind('keydown', 'f1', function(evt) {
alert('some message');
return false;
});
Firstly, why do you want to override F1? It is a well known convention that will launch the help for the desktop application (not your web application).
There may be no way around this, especially since you use preventDefault()
, stopPropagation()
and return false
.
精彩评论