HTML onbeforeunload Attribute

❮ HTML Attributes


<body onbeforeunload="return myFunction()">


The onbeforeunload attribute is invoked just before a page or object is unloaded from the user agent.

Standard Syntax

<element onbeforeunload="script">

Browser Support


Applies to:

The onbeforeunload attribute can be used on the following element:

Element Attribute
<body> onbeforeunload

Attribute Values

Value Description
script Specifies the script to be run on onbeforeunload
❮ HTML Attributes