Closed GoogleCodeExporter closed 9 years ago
I've tested the following in IE 7 and didn't get the behaviour you describe.
e.g. the
page was reloaded after my code was executed.
<html>
<head>
<script src="http://jshotkeys.googlepages.com/jquery-1.2.6.js"></script>
<script
src="http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.8.js"></script>
</head>
<body>
<script>
$(document).bind("keydown","F5",
function(event){
alert("F5");
event.keyCode = 0;
event.returnValue = false;
return false;
});
</script>
Original comment by Afro.Sys...@gmail.com
on 1 Jan 2009 at 5:57
That is exactly my point, it shouldn't because you put return false in your
function.
This will work in IE but not in FF:
<html>
<head>
<script src="http://jshotkeys.googlepages.com/jquery-1.2.6.js"></script>
<script
src="http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.8.js"></script>
</head>
<body>
<script>
$(document).bind("keydown","F5",
function(){
alert("F5");
event.keyCode = 0;
event.returnValue = false;
return false;
});
</script>
</body>
</html>
This will work in FF but not in IE:
<html>
<head>
<script src="http://jshotkeys.googlepages.com/jquery-1.2.6.js"></script>
<script
src="http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.8.js"></script>
</head>
<body>
<script>
$(document).bind("keydown","F5",
function(){
alert("F5");
return false;
});
</script>
</body>
</html>
This will work in both:
<html>
<head>
<script src="http://jshotkeys.googlepages.com/jquery-1.2.6.js"></script>
<script
src="http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.8.js"></script>
</head>
<body>
<script>
$(document).bind("keydown","F5",
function(){
alert("F5");
if (navigator.appVersion.indexOf('MSIE') != -1) {
event.keyCode = 0;
event.returnValue = false;
}
return false;
});
</script>
</body>
</html>
But what is the easiest way doing this? And shouldn't be part of the hotkeys
script
to disable the key after catching? And browser independent?
Original comment by mikebran...@gmail.com
on 1 Jan 2009 at 9:17
jQuery itself should do all these for you
From: http://docs.jquery.com/Events/bind
To cancel a default action and prevent it from bubbling up, return false:
$("form").bind("submit", function() { return false; })
To cancel only the default action by using the preventDefault method.
$("form").bind("submit", function(event){
event.preventDefault();
});
Let me know if it suites you.
Thanks for using hotkeys plugin
Original comment by Afro.Sys...@gmail.com
on 1 Jan 2009 at 9:51
Thanks, i haven't seen this page. But, after seeing it, the problem stays
exactly the
same:
<html>
<head>
<script src="http://jshotkeys.googlepages.com/jquery-1.2.6.js"></script>
<script
src="http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.8.js"></script>
</head>
<body>
<script>
$(document).bind("keydown","F5",
function(event){
alert("F5");
event.preventDefault();
});
</script>
</body>
</html>
This works only for FF and not for IE. (IE7)
Original comment by mikebran...@gmail.com
on 1 Jan 2009 at 10:33
Neither of the codes works in IE as you described - That is totally omiting the
Refresh action. In my case, IE showed the alert, and then, reloaded the page.
This is similar to what I described at
http://code.google.com/p/js-hotkeys/wiki/about
"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. "
Original comment by Afro.Sys...@gmail.com
on 11 Jan 2009 at 2:57
Original issue reported on code.google.com by
mikebran...@gmail.com
on 1 Jan 2009 at 5:20