Justin John Justin John - 2 months ago 9
jQuery Question

Possible to trigger JavaScript function on page reload?

Is it possible to trigger a JavaScript function when a user tries to reload the current page?

Answer

you mean confirm an "unload" whereby execute a function before the user leaves the current page.

<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>

OR

the jQuery version http://api.jquery.com/unload/

Comments