<body onUnload=””>

Sharing is caring!

Attribute of
<body> HTML Tag
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