--- title: unload slug: Web/API/Window/unload_event translation_of: Web/API/Window/unload_event ---
unload イベントは、文書または子リソースがアンロードされるときに発生します。
| バブリング | なし |
|---|---|
| キャンセル | 不可 |
| インターフェイス | {{domxref("Event")}} |
| イベントハンドラープロパティ | {{domxref("WindowEventHandlers/onunload", "onunload")}} |
以下のイベントの後に発生します。
文書は以下のような状態にあります。
unload イベントは文書ツリーにも続くことに注意してください。親フレームのアンロードは、子フレームの unload の前に行われます (以下の例を参照)。
<!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>
親フレームがアンロードされると、 console.log() のメッセージに記述された順序でイベントが発生します。
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('UI Events', '#event-type-unload', 'unload')}} | {{Spec2('UI Events')}} |
{{Compat("api.Window.unload_event")}}