当按下ESC按钮时,在keyDown事件处理程序中使用它时,location.reload不会重新加载页面。只在FF [英] location.reload doesn't reload the page when I'm using it in keyDown event handler when ESC is pressed. Only in FF
问题描述
我发现当按下ESC按钮的时候,当我从keyDown事件处理程序调用它的时候,location.reload()调用没有做任何事情。有谁知道一些解决方法如何重新加载页面?另外我发现 http://bugs.jqueryui.com/ticket/4922 ,看起来像这样问题已经解决了。
这是一个代码示例。
订阅事件:
jQuery(document).keydown(function(event){
if( event.keyCode == 27){
closeVideoPopup();
}
});
<$ p $ {code> function closeVideoPopup(){
jQuery('#fade,.window_container')。fadeOut(function(){
jQuery('#fade,a.close') .remove();
});
jQuery('ul.tabs').css('z-index','99');
jQuery('div.framing_slider')。css('z-index','9999');
location.reload();
返回false;
}
请注意这段代码在所有浏览器中都是完美的,除了FF 。
那是因为 Esc 在Firefox中触发后立即停止刷新。
使用 setTimeout
,所以 location.reload()
将在事件已经完成冒泡后执行。
jQuery ).keydown(function(event){
if(event.keyCode == 27){
setTimeout(closeVideoPopup,0);
}
});
或者更好,只要打电话给> event.preventDefault()
,所以 Esc 键不会取消页面重载:
$ p $ jQuery(document).keydown(function(event){
if(event.keyCode == 27){
event.preventDefault();
closeVideoPopup();
}
});
I find out that location.reload() call doesn't do anything when I called to it from keyDown event handler when ESC button is pressed. Does anybody knows some workaround how to reload the page? Also I find http://bugs.jqueryui.com/ticket/4922 and it looks like this problem is already fixed. Here is a sample of code. subscription to event:
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
closeVideoPopup();
}
});
And closeVideoPopup() method:
function closeVideoPopup() {
jQuery('#fade, .window_container').fadeOut(function(){
jQuery('#fade, a.close').remove();
});
jQuery('ul.tabs').css('z-index', '99');
jQuery('div.framing_slider').css('z-index', '9999');
location.reload();
return false;
}
Please note this code works perfect in all browsers except FF.
That's because the Esc key stops the refresh immediately after you fire it in Firefox.
Use a setTimeout
so the location.reload()
will execute after the event has already finished bubbling.
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
setTimeout(closeVideoPopup, 0);
}
});
Or better, just call event.preventDefault()
so the Esc key won't cancel the page reload:
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
event.preventDefault();
closeVideoPopup();
}
});
这篇关于当按下ESC按钮时,在keyDown事件处理程序中使用它时,location.reload不会重新加载页面。只在FF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!