I have a requirement to pop up a warning when a user attempts to leave the page, close the tab, or the browser itself. I was able to successfully build that with the window.onbeforeunload call below. The customer since revised the requirement to only have the pop-up when there is an unsaved edit on the web page.
I have added a sessionScope.Changed = true for the necessary fields onChange events on the page and reset the value to false when Save is clicked. I have confirmed that the sessionScope variable is being set properly. However, no matter what the value is - true or false, I cannot get the popup to fire correctly. I have also tried wrapping the if/then around the window.onbeforeunload line and left the function with just the return message.
Is the sessionScope simply not available on a page script or am I referencing it incorrectly or is it something else?
EDIT: My page uses a series of stack containers to simulate a tabbed interface. This construct appears to thwart the built-in enableModifiedFlag once the user clicks to another tab without saving, which is why I went down the path of the sessionScope variable.
Thank you in advance!
<script language="JavaScript"> var ch = '#{sessionScope.Changed}'; window.onbeforeunload = confirmExit; function confirmExit() { if (ch == true){ return "You have attempted to leave this page. If you have > made any changes without clicking the Save button, your changes will > be lost. Are you sure you want to exit this page?"; } else { return ""; } </script>