onload event
EVENT: onunload
onunload="action"
The
onunload
event occurs just before the HTML document is unloaded or removed from viewing (also when the page is refreshed). When this event happens, the code calls a function that performs a desired action. For example, you may want an alert box to appear that provides useful information to the user.
It can be used with either the
body
or
frameset
tags.
In contrast, the
onload
event occurs just after the HTML document is loaded for viewing.
In this example, the
onunload
event causes an alert box with a message to appear when you exit the page.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="eng">
<head>
<title>DevGuru XHTML onunload Tag Example</title>
</head>
<body>
<body
onunload="JavaScript:alert('Thank you for\nvisiting DevGuru!')"
>
Please exit or refresh this page to see output.
<br />
The alert box should appear.
</body>
</html>
Output:
Click to view and test output in a separate window
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information