.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.
Remember
// 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);
pagehide — page leaving
(or cached, when the browser uses bfcache)
How It Works
Listen.pagehide fires when the page is being hidden or unloaded.
persisted.true means the page may enter the back/forward cache.
Cleanup. Good place for beacons and session end logic.
Why. More reliable than unload for modern browsers.
Edge Cases & Pitfalls
Watch for these when reading legacy unload code or migrating.
removed
Missing in jQuery 3.x
$.fn.unload is undefined — calling it throws. Migrate to .on("unload").
target
Bind on window
Page unload is delivered to window. Prefer $(window).on("unload", fn).
dialogs
alert / confirm ignored
Most browsers block dialogs in unload. For leave prompts, use beforeunload carefully.
bfcache
Unload can break caching
Unload listeners often prevent the back/forward cache. Prefer pagehide for teardown.
Compatibility
Browser Support
.unload() existed from jQuery 1.0, was deprecated in 1.8, and removed in 3.0. In jQuery 3.x use .on("unload") / .trigger("unload"). The underlying unload event still varies by browser.
✓ Removed · jQuery 3.0+
jQuery .unload()
Unavailable in current jQuery. Legacy labs use jQuery 2.2.4. Prefer .on('unload') only when you must, and pagehide for new cleanup logic.
0%In jQuery 3.x
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.unload()Removed API
Bottom line: Do not ship .unload() on jQuery 3+. Migrate to .on('unload') / .trigger('unload'), or better: pagehide for session-end cleanup.
Analysis
Performance Notes
Approach
Cost
Best for
Light cleanup / storage write
Cheap
Legacy unload / pagehide
pagehide cleanup
Cheap
Modern session-end logic
Heavy sync work on unload
Expensive / dropped
Avoid — browsers may kill it
Keep leave-time work tiny. Prefer navigator.sendBeacon or async patterns started earlier — do not rely on long unload handlers.
Remember
Key Takeaways
Role: legacy bind/trigger for the window unload event.
Migrate:$(window).on("unload", fn) — required on jQuery 3+.
Trigger: use .trigger("unload") instead of no-arg .unload().
Prefer:pagehide for modern page-lifecycle cleanup.
One line:.unload() is removed — use .on("unload") to migrate, and pagehide for new cleanup.
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.