<body onUnload="">

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
Attribute of
HTML Body Tag: Master The Most Important HTML Element Now
What does <body onUnload=""> do?
Fires a script when the visitor leaves the page.

The onUnload attribute is an event handler that instructs the browser to run a script when the visitor leaves the page.

Example usage

<body onUnload="script">

Points to be aware of

body event handlers act on the browser window, so the onUnload is commonly used to bring up JavaScript alert when the visitor exits a website. Some visitors may find this behavior unhelpful, so it’s best used sparingly.

Claire is seasoned technical writer, editor, and HTML enthusiast. She writes for HTML.com and runs a content agency, Red Robot Media.

Browser Support for onUnload

iefirefoxchromeedgesafariopera
AllAllAllAllAllAll