lovespring
lovespring

Reputation: 19559

How to stop window unloading?

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

Upvotes: 4

Views: 6654

Answers (3)

Topher Fangio
Topher Fangio

Reputation: 20667

Look at the unload at the bottom of this page.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190907

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>

Upvotes: 7

Erik
Erik

Reputation: 20712

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?";
  }

Upvotes: 3

Related Questions