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

이 글은 편집 검토가 필요합니다. 도울을 줄 수 있는 방법을 살펴보세요.

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

The unload event is fired when the document or a child resource is being unloaded.

It is fired after:

  1. beforeunload (cancellable event)
  2. pagehide

The document is in a particular state:

  • all the resources still exist (img, iframe etc.)
  • nothing is visible anymore to the end user
  • UI interactions are ineffective (window.open, alert, confirm etc.)
  • an error won't stop the unloading workflow

Please note that the unload event also follows the document tree: parent frame unload will happen before child frame unload (see example below).

General info

Specification
DOM L3
Interface
UIEvent if generated from a user interface, Event otherwise.
Bubbles
No
Cancelable
No
Target
defaultView, Document, Element
Default Action
None.

Properties

Property Type Description
target Read only EventTarget The event target (the topmost target in the DOM tree).
type Read only DOMString The type of event.
bubbles Read only Boolean Whether the event normally bubbles or not
cancelable Read only Boolean Whether the event is cancellable or not?
view Read only WindowProxy document.defaultView (window of the document)
detail Read only long (float) 0.

Example

<!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>

Below, the content of 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>

When the parent frame is unloaded, events will be fired in the order described by console.log messages.

Reference

문서 태그 및 공헌자

 이 페이지의 공헌자: ryanmurakami, teoli, Sheppy, ethertank, oncletom, louisremi
 최종 변경: ryanmurakami,