View Full Version : window.onbeforeunload should be fired only in some scenarios

13 Aug 2012, 3:42 AM
Hi guys,

I have the following scenario:

I have a page and an edit button after clicking of which the same page opens in a separate window for the user to edit.

The user should be prompted before he navigates away only from the edit mode of that page.It is 'Are you sure you want to navigate blah blah blah..?" the usual message.This message is not required when the user tries to navigate from any other page of the application.Though I have tried to constrain the firing of the event using an 'if' condition to check if the user is in that page or not , it doesn't work.I get the message every time I try to close a window or navigate away from any page of the application.

Do you think onbeforeunload is the proper event to be handled in this scenario?

Please help!


16 Sep 2012, 5:42 PM
See if this helps: