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]
# 1
You can use the Javascript onunload event.
BalusCa at 2007-7-9 5:39:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

efratba at 2007-7-9 5:39:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Hi,Can you do something like saving the current page in session scope.. so that you can retrive the value..Regards,joe
w4ca at 2007-7-9 5:39:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
No .. When you don't submit the changed values, then they won't be saved ;)
BalusCa at 2007-7-9 5:39:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
It's OK. I don't want to save the changes.I just want to have the ability to cancel the page unload, and give the user a second chance to save the changes.Is it possible?
efratba at 2007-7-9 5:39:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...