HTML event attribute onunload








The onunload attribute event is triggered when a page has unloaded by navigating to other page or by closing the browser window.

What's new in HTML5

None.

Syntax

<element onunload="script or Javascript function name">

Supported Tags

<body>

Browser compatibility

onunload No Yes Yes Yes Yes




Example

<!DOCTYPE html>
<html>
<head>
<script>
function goodbye(){<!--   ww  w .j ava  2s. c  om-->
   alert("on unload");
}
</script>
</head>

<body onunload="goodbye()">

<p>Close this window or press F5 to reload the page.</p>

</body>
</html>

Click to view the demo