A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/zh-CN/docs/Web/API/Window/unload_event below:

unload - Web API | MDN

unload

当文档或一个子资源正在被卸载时,触发 unload 事件。

可冒泡(Bubbles) No 可取消(Cancelable) No 接口(Interface) Event 事件处理程序属性(Event handler property) onunload

它在下面两个事件后被触发:

  1. beforeunload (可取消默认行为的事件)
  2. pagehide

文档处于以下状态:

请注意unload事件也遵循文档树:父 iframe 会在子 iframe 卸载前卸载 (参考下面的例子).

示例
<!doctype html>
<html>
  <head>
    <title>Parent Frame</title>
    <script>
      window.addEventListener("beforeunload", function (event) {
        console.log("I am the 1st one.");
      });
      window.addEventListener("unload", function (event) {
        console.log("I am the 3rd one.");
      });
    </script>
  </head>
  <body>
    <iframe src="child-frame.html"></iframe>
  </body>
</html>

下面是 child-frame.html 的内容:

<!doctype html>
<html>
  <head>
    <title>Child Frame</title>
    <script>
      window.addEventListener("beforeunload", function (event) {
        console.log("I am the 2nd one.");
      });
      window.addEventListener("unload", function (event) {
        console.log("I am the 4th and last one…");
      });
    </script>
  </head>
  <body>
    ☻
  </body>
</html>

当父 iframe 被卸载,事件将按 console.log() 消息描述的顺序触发。

规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4