how to trigger an event on reload js

JavaScript
<html>
<head>

<script type="text/javascript">
function mymessage()
{
    //this is the sample function code executed on "unload"
    alert("This message was triggered from the onunload event")
}
</script>
</head>

<body onunload="mymessage()">

<p>close this window</p>
</body>

</html>
Source

Also in JavaScript: