Justin John Justin John - 29 days ago 6x
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?


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


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

<body onunload="mymessage()">

<p>close this window</p>



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