location.reload 不会重新加载页面,当我在按下 ESC 时在 keyDown 事件处理程序中使用它时。仅在FF中



我发现 location.reload() 调用在按下 ESC 按钮时从 keyDown 事件处理程序调用它时没有做任何事情。有没有人知道如何重新加载页面的一些解决方法?我也找到了 http://bugs.jqueryui.com/ticket/4922,看起来这个问题已经解决了。 下面是一个代码示例。 订阅活动:

jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
closeVideoPopup();
}
});

和 closeVideoPopup() 方法:

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;

}

请注意,此代码在除FF以外的所有浏览器中都完美运行

这是因为Esc键在 Firefox 中触发刷新后会立即停止刷新。

使用setTimeout,以便在事件完成冒泡后执行location.reload()

jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
setTimeout(closeVideoPopup, 0);
}
});

小提琴


或者更好的是,只需调用event.preventDefault(),这样Esc键就不会取消页面重新加载:

jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
event.preventDefault();
closeVideoPopup();
}
});

小提琴

最新更新