1 line
2.3 KiB
JSON
1 line
2.3 KiB
JSON
{"name":"unload","type":"method","title":".unload()","deprecated":"1.8","removed":null,"desc":"Bind an event handler to the \"unload\" JavaScript event.","categories":["events/document-loading","version/1.0","version/1.4.3","deprecated/deprecated-1.8"],"entries":[{"return":"jQuery","signatures":[{"added":"1.0","argument":{"desc":"A function to execute when the event is triggered.","name":"handler(eventObject)","type":"Function"}},{"added":"1.4.3","argument":[{"desc":"A plain object of data that will be passed to the event handler.","name":"eventData","type":"Object","optional":"true"},{"desc":"A function to execute each time the event is triggered.","name":"handler(eventObject)","type":"Function"}]}],"examples":{"desc":"To display an alert when a page is unloaded:","code":"\n$( window ).unload(function() {\n alert( \"Bye now!\" );\n});\n "},"longdesc":"\n <p>This method is a shortcut for <code>.on( \"unload\", handler )</code>.</p>\n <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>\n <div class=\"warning\">\n <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 proprietary <code>beforeunload</code> event.</p>\n </div>\n <p>Any <code>unload</code> event handler should be bound to the <code>window</code> object:</p>\n <pre><code>\n$( window ).unload(function() {\n alert( \"Handler for .unload() called.\" );\n});\n </code></pre>\n <p>After this code executes, the alert will be displayed whenever the browser leaves the current page.\nIt is not possible to cancel the <code>unload</code> event with <code>.preventDefault()</code>. This event is available so that scripts can perform cleanup when the user leaves the page.\n </p>\n "}]} |