When we exit a page or close the browser tab we can trigger an event by using onunload . However when we close the browser then it can't be displayed. To check this code open the demo page in one new tab and then try to close the tab or visit to a different URL to exit the page.
The source code of the demo page is here.
The source code of the demo page is here.
This will work on Firefox and Internet Explorer borwer
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Demo of onunload event trigger</title>
</head>
<body onunload="alert('thanks for visiting plus2net')";>
You should get one alert message when you close this page or exit this page.
</body>
</html>