You need to sign in to do that
Don't have an account?

OnUnload Event for a visual force page
I am trying to capture the 'onunload' javascript event on a visual force page. Adding a html body tag and then adding the onunload event dosnt work. How can I capture this event.
In general I am trying to prompt the user when they move away from this page (either to another tab or link within the browser or if they decide to close the browser).
Thanks
In general I am trying to prompt the user when they move away from this page (either to another tab or link within the browser or if they decide to close the browser).
Thanks
Hi Gays,
I know I am late. But just to close this discussion.
I Changed
and it’s working for me.
Cheers!
Rajan Jasuja
All Answers
I used your code by embedding it after the <apex:page> tag and unfortunately I can still move away to other pages without displaying the alert.
Also I see you dont use the alert function -- ?? how is the message displayed that case. Does setting a value to window.onbeforeunload mean that 1) the property is now 'active' aka will be triggered 2) display the expression result specfiied in the property in a alert window ?
Thanks
It provides a notice, similar to an alert when I go to another page (or tab in SDFC) or when I try to close the browser from the window control.
The message is passed into the window event and then get's displayed, you don't need to use an alert box.
Depending on what you are trying to do, this could have issues, and should have some more advanced features before implementing in production. For example, you might want to have another variable that gets tested to see if the function should fire or not, if the user has saved the information (for example) you set the "saveddata" variable to true, and don't generate the message. The other condition that can be annoying is that a refresh of the page, or even the section the code is in will cause the onbeforeunload event to fire.
Good Luck!
PAGE:
Thanks
Message Edited by EPSWDEV on 01-12-2009 11:44 AM
Hi Gays,
I know I am late. But just to close this discussion.
I Changed
and it’s working for me.
Cheers!
Rajan Jasuja
Hi Rajan,Jim and other
I know this topic has been addressed long bank.However,I need pretty much the same stuff.Rajan,your suggestion really works and it is helpful
My question is.How do I override the message which I see in the message box.
Message is:-This page is asking you to confirm that you want to leave - data you have entered may not be saved.
How do I override the above message,Atleast,I need to get rid of the red lines ?
Is there some other way of showing dialog box with the option stay or leave on the current page?
I have visual force tab and person clicks on the tab and does some wotk in the application underneath the tab and then saves some report.
He is not entering any data in there.
I want to get rid of the lines in red
Can somebody throw some light on it.?
Code that I am trying is pretty much what you see above?
Thanks,
Trick0123
Hi Rajan,Jim and other
I know this topic has been addressed long bank.However,I need pretty much the same stuff.Rajan,your suggestion really works and it is helpful
My question is.How do I override the message which I see in the message box.
Message is:-This page is asking you to confirm that you want to leave - data you have entered may not be saved.
How do I override the above message,Atleast,I need to get rid of the red lines ?
Is there some other way of showing dialog box with the option stay or leave on the current page?
I have visual force tab and person clicks on the tab and does some wotk in the application underneath the tab and then saves some report.
He is not entering any data in there.
I want to get rid of the lines in red
Can somebody throw some light on it.?
Code that I am trying is pretty much what you see above?
Thanks,
Trick0123
Hello, I tried out this solution on a custom visual force page used for editing purposes. The problem I am running into is the user is the pop-up will appear whenever the user natvigates away from the page, like during a "save" or "cancel" operation. However I only want the warning to pop-up when the user closes the tab.
Also, the pop-up will appear in other places such as entering a value for a lookup field and clicking on "today"'s date on a date field.
For the first part of the problem, I think it might be possible to modify the controller and use a boolean to stop the pop-up (however I haven't explored it yet).
But for the second part, it seems like something that is out of my control (where the pop-up is appearing for date fields and lookup fields).
I would appreciate any ideas/inputs, thanks a lot!