0

I am checking when the user closes the browser window, if he says ok, how i do I trigger some action, like opening another window or saving a form. If he chooses "cancel", it should stay in the same page (which is working now). pls share some idea on how to approach this issue

Sample Code

Sullan
  • 1,147
  • 2
  • 22
  • 39
  • Possible duplicate: http://stackoverflow.com/questions/4650692/way-to-know-if-user-clicked-cancel-on-a-javascript-onbeforeunload-dialog – Zirak Apr 20 '11 at 05:11

1 Answers1

0

You cannot react to the user clicking on the "Leave this page" button. This is by design of the browser: if the user wants to leave, let him go.

If the user chooses to cancel, you can try a technique found in this answer to similar question to execute some custom code like saving changes or the like.

Community
  • 1
  • 1
Oliver
  • 9,239
  • 9
  • 69
  • 100