Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

window.onunload

概述

当页面关闭后,会触发unload事件.

语法

window.onunload = funcRef;
  • funcRef 是一个函数名.

例子

<html>
<head>

<title>onunload test</title>

<script type="text/javascript">

window.onunload = unloadPage;

function unloadPage()
{
 alert("unload event detected!");
}
</script>
</head>

<body>
<p>Reload a new page into the browser<br />
 to fire the unload event for this page.</p>
<p>You can also use the back or forward buttons<br />
 to load a new page and fire this event.</p>
</body>
</html>

注意事项

如果你的浏览器有禁止页面主动弹窗的功能,那么在onunload 事件的事件处理函数中调用的window.open()方法都会被当成恶意弹窗而被阻止.

规范

DOM Level 0 不属于任何标准.

文档标签和贡献者

 此页面的贡献者: teoli, AshfaqHossain, ziyunfei
 最后编辑者: AshfaqHossain,