Justin John Justin John - 1 year ago 90
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 Source

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/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download