When the user clicks the link to leave this page, a message box pops up:
$(window).unload(function(){ alert("Goodbye!"); });
Try it yourself
When the user leaves the page, the unload event occurs.
Specifically, the unload event will be emitted when the following occurs:
Click a link to leave the page
New URL typed in the address bar
Use the forward or back buttons
Close the browser
Reload the page
The unload() method binds the event handler program to the unload event.
The unload() method only applies to window objects.
event.unload(function)
Parameters | Description |
---|---|
function | Required. Specifies the function to run when the unload event is triggered. |
load( url, [data], [callback]) loads the remote HTML file code and inserts it into the DOM. The GET method is used by default - automatically converted to POST method when passing additional parameters. In jQuery 1.2, you can specify a selector to filter the loaded HTML document, and only the filtered HTML code will be inserted into the DOM. The syntax is "url #some > selector".
has three parameters, namely:
url — (String) — URL of the HTML webpage to be loaded.
data (optional) — (Map,String) — Key/value data sent to the server. In jQuery 1.3 it is also possible to accept a string .
callback (optional) — Callback function when Callback is loaded successfully.
HTML code:
jQuery Links:
jQuery Code:
$("#feeds").load("feeds.html");
jQuery code:
$("#feeds").load("feeds.php", {limit: 25}, function(){
alert("The last 25 entries in the feed have been loaded");
});
unload(fn) Bind a handler function to the unload event of each matching element.
Parameters: fn — Function The processing function bound in the unload event of each matching element.
Example: A
warning box pops up when the page is unloaded:jQuery code:
$(window).unload( function () { alert("Bye now!" ); } );
load(url, [data], [callback]) Loads the remote HTML file code and inserts it into the DOM. The GET method is used by default - automatically converted to POST method when passing additional parameters. In jQuery 1.2, you can specify a selector to filter the loaded HTML document, and only the filtered HTML code will be inserted into the DOM. The syntax is "url #some > selector". has three parameters, namely:
url — (String) — URL of the HTML webpage to be loaded.
data (optional) — (Map,String) — Key/value data sent to the server. In jQuery 1.3 it is also possible to accept a string.
callback (optional) — Callback function when Callback is loaded successfully.
HTML code:
jQuery Links:
jQuery Code:
$("#feeds").load("feeds.html");
jQuery code:
$("#feeds").load("feeds.php", {limit: 25}, function(){
alert("The last 25 entries in the feed have been loaded");
});
unload(fn) Bind a handler function to the unload event of each matching element.
Parameters: fn — Function The processing function bound in the unload event of each matching element.
Example: A warning box pops up when the page is unloaded:
jQuery code:
$(window).unload( function () { alert("Bye now!"); } );
The above is the detailed content of Use of jQuery load and unload functions. For more information, please follow other related articles on the PHP Chinese website!