Cas*_*yas 6 javascript jquery google-chrome
我正在使用以下代码段在页面关闭之前触发警报,但Chrome似乎忽略了该消息并显示其默认消息"您是否要离开此站点?您所做的更改可能无法保存".如何让chrome显示我的消息而不是默认消息?
window.onbeforeunload = function(e) {
e.returnValue = "A search is in progress, do you really want to stop the search and close the tab?";
return "A search is in progress, do you really want to stop the search and close the tab?";
}
Run Code Online (Sandbox Code Playgroud)
更新:在 Chrome 中已弃用: https: //developers.google.com/web/updates/2016/04/chrome-51-deprecations ?hl=en
请尝试以下操作:
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'A search is in progress, do you really want to stop the search and close the tab?';
}
// For Safari
return 'A search is in progress, do you really want to stop the search and close the tab?';
};
Run Code Online (Sandbox Code Playgroud)
我在 Chrome 中收到的消息(自定义和默认):
搜索正在进行中,您确实要停止搜索并关闭选项卡吗?
您确定要离开此页面吗?
来源jsFiddle
归档时间: |
|
查看次数: |
16162 次 |
最近记录: |