Latest web development tutorials

HTML onunload event properties

HTML Event Attributes HTML Event Attributes

Examples

Execute when the user closes a page JavaScript:

<body onunload="goodbye()">

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support onunload event attributes


Definition and Usage

onunload attribute triggered when the user closes a page.

onunload the user leaves the page (by clicking on the link, submit a form, close the browser window, etc.) trigger.

Note: If you reload the page, unload event is triggered ( the onload event).


Differences between HTML 4.01 and HTML5

None.


grammar

<elementonunload=" script ">

Property Value

描述
script 规定该onunload事件触发时执行的脚本。


HTML Event Attributes HTML Event Attributes