tags:

views:

159

answers:

3

when user click a another link or refresh the page, the window will unload, how to prevent/confirm it?

+2  A: 

I think the onbeforeunload event handler would be what you're looking for.

Try the following:

  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
  }
Erik
thank you ......
lovespring
+3  A: 

From here http://bytes.com/topic/javascript/insights/825556-using-onbeforeunload-javascript-event

<script type="text/javascript">
     window.onbeforeunload = function(){ return 'Your Returned String Goes Here';}
</script>
Daniel A. White
A: 

Look at the unload at the bottom of this page.

Topher Fangio
Can you add some content to this answer please? Imagine links didn't exist, how useful would this be?
Jonathan Sampson
thank you ......
lovespring
@Jonathan Sampson - Good point. I'll do that next time. I'd update this answer, but the accepted one is basically the same.
Topher Fangio