Javascript safari中未保存的工作警告失败

Javascript safari中未保存的工作警告失败,javascript,html,browser,safari,Javascript,Html,Browser,Safari,我需要警告意外关闭的应用程序用户,他们有未保存的工作。我的研究表明,不同的浏览器行为不同;通过此链接: 我得到的代码在: IE11,Chrome45,firefox40,opera31。。在safari 5.1.7(在windows 8下)上失败 测试代码html和js: <!DOCTYPE HMTL> <meta charset="UTF-8"> <html> <head> <title>Unsaved Work Warning<

我需要警告意外关闭的应用程序用户,他们有未保存的工作。我的研究表明,不同的浏览器行为不同;通过此链接: 我得到的代码在: IE11,Chrome45,firefox40,opera31。。在safari 5.1.7(在windows 8下)上失败

测试代码html和js:

<!DOCTYPE HMTL>
<meta charset="UTF-8">
<html>
<head>
<title>Unsaved Work Warning</title>
</head>

 <body >
        <h1>Try to close page and get confirm warning
<script language="javascript">
function goodbye(e) {
    if(!e) e = window.event;
    //e.cancelBubble is supported by IE - this will kill the bubbling    process.
    e.cancelBubble = true;
    e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog

    //e.stopPropagation works in Firefox.
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
}
window.onbeforeunload=goodbye;

</script>    
</body>
</html>

未保存的工作警告
尝试关闭页面并获得确认警告
功能(e){
如果(!e)e=window.event;
//e、 IE支持cancelBubble-这将终止冒泡过程。
e、 取消气泡=真;
e、 returnValue='确实要离开吗?';//这将显示在对话框上
//e、 stopPropagation在Firefox中工作。
如果(如停止播放){
e、 停止传播();
e、 预防默认值();
}
}
window.onbeforeunload=再见;
看起来我需要插入代码来检测nav out(包括选项卡和浏览器关闭),并为safari发出“未保存的工作”警告


< Safari专家请告知。

您的代码依赖于Windows事件的支持,请考虑使用ADDeVistListEnter设置侦听器。或者使用
window.onload=function(){bye(event)}我正在寻找关闭时触发的safari特定事件。如果你有一个经过验证的代码来捕获这个,告诉我!至于尝试这个和那个,我已经尝试了关于这个主题的每一段代码,我可以找到,变戏法或猜测。我来了,还差一次旅行。