aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/api/windoweventhandlers/onunload/index.html
blob: 111f87edf239c645179d24f71ad4823340fe2bf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
title: window.onunload
slug: Web/API/WindowEventHandlers/onunload
translation_of: Web/API/WindowEventHandlers/onunload
original_slug: Web/API/GlobalEventHandlers/onunload
---
<p>{{ ApiRef() }}</p>
<h3 id="Summary" name="Summary">Test Summary</h3>
<p>The unload event is raised when the document is unloaded.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">window.onunload = <em>funcRef</em>;
</pre>
<ul>
 <li><code>funcRef</code> is a reference to a function.</li>
</ul>
<h3 id="Example" name="Example">Example</h3>
<pre>&lt;html&gt;
&lt;head&gt;

&lt;title&gt;onunload test&lt;/title&gt;

&lt;script type="text/javascript"&gt;

window.onunload = unloadPage;

function unloadPage()
{
 alert("unload event detected!");
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt;Reload a new page into the browser&lt;br /&gt;
 to fire the unload event for this page.&lt;/p&gt;
&lt;p&gt;You can also use the back or forward buttons&lt;br /&gt;
 to load a new page and fire this event.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3 id="Notes" name="Notes">Notes</h3>
<p>Note that using this event handler in your page prevents Firefox 1.5 from caching the page in the in-memory bfcache. See <a href="/En/Using_Firefox_1.5_caching" title="En/Using_Firefox_1.5_caching">Using Firefox 1.5 caching</a> for details.</p>
<p>Browsers equipped with pop-up window blockers will ignore all window.open() method calls in onunload event handler functions.</p>
<h3 id="Specification" name="Specification">Specification</h3>
<p>{{ DOM0() }}</p>
<p>{{ languages( {"zh-cn": "zh-cn/DOM/window.onunload" } ) }}</p>