You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<desc>An object containing data that will be passed to the event handler.</desc>
16
15
</argument>
@@ -20,31 +19,24 @@
20
19
</argument>
21
20
</signature>
22
21
<longdesc>
23
-
<divclass="warning">
24
-
<p>Note: This API has been removed in jQuery 3.0; please use <code>.on( "load", handler )</code> instead of <code>.load( handler )</code> and <code>.trigger( "load" )</code> instead of <code>.load()</code>.</p>
25
-
</div>
26
-
<p>This method is a shortcut for <code>.on( "load", handler )</code>.</p>
27
22
<p>The <code>load</code> event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the <code>window</code> object.</p>
28
23
<p>For example, consider a page with a simple image:</p>
29
24
<pre><code>
30
25
<img src="book.png" alt="Book" id="book">
31
26
</code></pre>
32
27
<p>The event handler can be bound to the image:</p>
33
28
<pre><code>
34
-
$( "#book" ).load(function() {
35
-
// Handler for .load() called.
36
-
});
29
+
$( "#book" ).on( "load", function() {
30
+
// Handler for `load` called.
31
+
});
37
32
</code></pre>
38
33
<p>As soon as the image has been loaded, the handler is called.</p>
39
34
<p>In general, it is not necessary to wait for all images to be fully loaded. If code can be executed earlier, it is usually best to place it in a handler sent to the <code>.ready()</code> method.
40
35
</p>
41
-
<divclass="warning">
42
-
<p>The Ajax module also has a method named <code><ahref="/load/">.load()</a></code>. Which one is fired depends on the set of arguments passed.</p>
43
-
</div>
44
36
<divclass="warning">
45
37
<p>
46
38
<b>Caveats of the <code>load</code> event when used with images</b>
47
-
<p>A common challenge developers attempt to solve using the <code>.load()</code> shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:</p>
39
+
<p>A common challenge developers attempt to solve using the <code>load</code> shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:</p>
48
40
<ul>
49
41
<li>It doesn't work consistently nor reliably cross-browser</li>
50
42
<li>It doesn't fire correctly in WebKit if the image src is set to the same src as before</li>
<desc>A plain object of data that will be passed to the event handler.</desc>
15
15
</argument>
@@ -18,35 +18,46 @@
18
18
<argumentname="eventObject"type="Event" />
19
19
</argument>
20
20
</signature>
21
-
<desc>Bind an event handler to the "unload" event.</desc>
22
21
<longdesc>
23
-
<divclass="warning">
24
-
<p>Note: This API has been removed in jQuery 3.0; please use <code>.on( "unload", handler )</code> instead of <code>.unload( handler )</code> and <code>.trigger( "unload" )</code> instead of <code>.unload()</code>.</p>
25
-
</div>
26
-
<p>This method is a shortcut for <code>.on( "unload", handler )</code>.</p>
27
22
<p>The <code>unload</code> event is sent to the <code>window</code> element when the user navigates away from the page. This could mean one of many things. The user could have clicked on a link to leave the page, or typed in a new URL in the address bar. The forward and back buttons will trigger the event. Closing the browser window will cause the event to be triggered. Even a page reload will first create an <code>unload</code> event.</p>
28
23
<divclass="warning">
29
24
<p>The exact handling of the <code>unload</code> event has varied from version to version of browsers. For example, some versions of Firefox trigger the event when a link is followed, but not when the window is closed. In practical usage, behavior should be tested on all supported browsers and contrasted with the similar <code>beforeunload</code> event.</p>
30
25
</div>
31
26
<p>Any <code>unload</code> event handler should be bound to the <code>window</code> object:</p>
32
27
<pre><code>
33
-
$( window ).unload(function() {
34
-
return "Handler for .unload() called.";
35
-
});
28
+
$( window ).on( "unload", function() {
29
+
return "Handler for `unload` called.";
30
+
});
36
31
</code></pre>
37
32
<p>This event is available so that scripts can perform cleanup when the user leaves the page. Most browsers will ignore calls to <code>alert()</code>, <code>confirm()</code> and <code>prompt()</code> inside the event handler. The string you return may be used in a confirmation dialog, but not all browsers support this. It is not possible to cancel the <code>unload</code> event with <code>.preventDefault()</code>.</p>
38
33
</longdesc>
39
34
<example>
40
35
<desc>To display an alert when a page is unloaded:</desc>
41
36
<code><![CDATA[
42
-
$( window ).unload(function() {
37
+
$( window ).on( "unload", function() {
43
38
return "Bye now!";
44
-
});
39
+
});
45
40
]]></code>
46
41
</example>
47
42
<categoryslug="events/document-loading"/>
48
43
<categoryslug="version/1.0"/>
49
-
<categoryslug="version/1.4.3"/>
50
-
<categoryslug="deprecated/deprecated-1.8"/>
51
-
<categoryslug="removed"/>
44
+
<categoryslug="version/1.7"/>
45
+
</entry>
46
+
47
+
<entrytype="method"name="trigger"return="jQuery">
48
+
<title>unload event</title>
49
+
<desc>Trigger the "unload" event on an element.</desc>
50
+
<signature>
51
+
<added>1.0</added>
52
+
<argumentname=""unload""type="string">
53
+
<desc>The string <code>"unload"</code>.</desc>
54
+
</argument>
55
+
</signature>
56
+
<longdesc>
57
+
<p>See the description for <ahref="#on1"><code>.on( "unload", ... )</code></a>.</p>
0 commit comments