window.onbeforeunload / window.onunload无法在chrome中工作以检测浏览器关闭事件。需要一些帮助!
答案 0 :(得分:2)
检查一下 http://help.dottoro.com/ljhtbtum.php
示例 http://help.dottoro.com/external/examples/ljhtbtum/onbeforeunload_1.htm
码
<head>
<script type="text/javascript">
function OnBeforeUnLoad () {
return "All data that you have entered will be lost!";
}
</script>
</head>
<body onbeforeunload="return OnBeforeUnLoad ()">
<b>Close this window or press F5 to reload the page.</b>
<br /><br />
<form>
User name: <input type="text" name="username" />
<br />
City: <input type="text" name="city" />
</form>
</body>