【发布时间】:2014-08-20 12:58:34
【问题描述】:
var isRefresh = false;
$(document).on("keydown", function(e) {
if (e.which === 116 || e.which == 17 || e.which == 1)
{
isRefresh = true;
}
});
$(window).bind('click', function(event) {
if(event.target.href || event.which == 1)
$(window).unbind('beforeunload');
});
$(window).bind('beforeunload', function(event) {
if(!isRefresh){
var e = window.event;
if (e) {
e.returnValue = 'Are you sure?';
}
// For Safari
if (navigator.appVersion.indexOf("Chrome/") != -1){
return '';
}
else{
return 'Are you sure?'
}
}
});
此脚本用于关闭选项卡,F5。根据我的要求,在按下浏览器 URL 时,浏览器的后退按钮不应出现提示。整体提示应仅在关闭选项卡时出现。
【问题讨论】:
标签: browser