Check if updates were made before page unload
Hi,
I have a web application using the JSF framework.
Some of the pages have editable parameters & a "Set" commandButton.
If one of these parameters was changed and the set button wasn't pressed, I would like to alert the user before the page is unloaded.
If the user chooses to discard changes the new URL will be loaded.
But if not - I would like to leave the current page unchanged (without reloading it, to keep the changes).
How can I do it?
Thanks a lot,
Efrat
[526 byte] By [
efratba] at [2007-11-26 18:08:09]

# 2
Hi,
Thanks for your reply.
I tried using the javascript onunload event.
I'm not sure that I know what to do with it...
I did something like this:
<BODY CLASS="BgGray" onclick="javascript:closeAllMenus()" onunload="javascript:checkValueChanged()">
where checkValueChanged is defined as follows:
function checkValueChanged()
{
if (valueChanged == true)
{
if (confirm('One or more of the page properties were configured. Discard changes?')==false)
{
parent.main.location="<%=request.getHeader("Referer")%>";
}
}
}
When the user presses the OK button of the confirm dialog, the new URL is reloaded, when cancel is selected, the current URL is reloaded.
But the problem is that I don't want to reload the current page, I want to do nothing, because if the current page is reloaded I lose all the changes that were made.
How do I stop the new page from reloading without reloading the current page again?
Thanks a lot,
Efrat