我需要警告应用程序用户意外关闭他们有未保存的工作。我的研究显示不同浏览器的行为不同唉通过这个链接: http://www.openjs.com/scripts/events/exit_confirmation.php 我得到的代码适用于: 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>
看起来我需要坚持使用代码来检测导出(包括标签和浏览器关闭)并为safari发出“未保存的工作”警告。
Safari专家请指教。