HTML onbeforeunload Attribute

❮ HTML Attributes

Example

<body onbeforeunload="return myFunction()">

Meaning

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




Standard Syntax

<element onbeforeunload="script">



Browser Support




Status




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