<html> <head> <script language="JavaScript"><!-- function confirmIEleave() { event.returnValue = "Are you sure you want to leave this page?"; }function confirmNSLeave(iWindow) { if (!document.layers) return; if (!iWindow.closed) { if (!confirm('Are you sure you want to leave this page?')) window.location.href = 'javascript:void(0)'; } } //--></script> </head><body onbeforeunload="confirmIELeave()" onUnload="confirmNSLeave()"><p> Navigate to another page to fire the before unload event. </p></body> </html>
用onunload的话,点refresh也会弹出警告窗口,所以这不是我想要的结果。
我的意思就是在close事件发生之前想处理一些事情,怎样铺捉到浏览器的关闭事件。
<html>
<head>
<script language="JavaScript"><!--
function unload() {
if (confirm("Do ya really wanna go?"))
}
//--></script></head><body onUnload="unload()">
...
</body>
</html>
<!--
function window_onunload() {
//执行删除机器文件操作,呵呵
alert("您正在关闭窗口!");
}
-->
</script>
<head>
<script language="JavaScript"><!--
function confirmIEleave() {
event.returnValue = "Are you sure you want to leave this page?";
}function confirmNSLeave(iWindow) {
if (!document.layers) return;
if (!iWindow.closed) {
if (!confirm('Are you sure you want to leave this page?'))
window.location.href = 'javascript:void(0)';
}
}
//--></script>
</head><body onbeforeunload="confirmIELeave()" onUnload="confirmNSLeave()"><p>
Navigate to another page to fire the before unload event.
</p></body>
</html>
海盗,怎样激活你的window_onunload()函数?