.unload() was jQuery’s shorthand (since 1.0) for binding or triggering the browser unload event — almost always on window. It is gone in jQuery 3.x. Use .on("unload") / .trigger("unload"), or prefer pagehide for modern cleanup.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Removed in jQuery 3.0 — only works in 1.x / 2.x
$(window).unload(function () {
// page is leaving
});
$(window).unload(); // trigger
// Modern replacements
$(window).on("unload", handler);
$(window).trigger("unload");
// Often better for cleanup today
$(window).on("pagehide", handler);
Call
What it does
window
Standard target for page unload
handler
function(event)
eventData
Extra data as event.data
jQuery version
Method missing in 3.x
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
In old code, bind with $(window).unload(handler) (jQuery 1.x / 2.x only).
Click fire → Handler ran via .unload()
No real page navigation required
How It Works
Bind. A handler is registered with the shorthand.
Click. No-arg .unload() triggers the event.
Run. Bound handlers execute immediately.
Frequently Asked Questions
.unload(handler) bound a function to the browser unload event — typically on $(window). .unload() with no arguments triggered unload handlers. It was shorthand for .bind("unload", handler) or .trigger("unload"). Removed in jQuery 3.0.
No. .unload() was deprecated in jQuery 1.8 and removed in jQuery 3.0. Calling it in jQuery 3.x throws because $.fn.unload is undefined. Use $(window).on("unload", handler) and $(window).trigger("unload") instead.
They target the same browser unload event. .unload() was sugar removed in 3.0. .on("unload", fn) is the supported API in jQuery 3.x and supports eventData, namespaces, and .off() cleanup.
Generally no. Browsers treat unload as unreliable — it can break the back/forward cache and may not fire on mobile tab switches. Prefer pagehide or visibilitychange for cleanup; use beforeunload only for unsaved-changes warnings.
jQuery 3.0 removed event shorthands that shared names with other APIs or had limited value. Prefer the explicit .on() / .trigger() forms for unload.