Solved
Confirm close of browser window. (IE5)
Posted on 2002-07-19
I only need an IE5 solution to this if it makes it easier. (love homogenous intranet environments)
I'd like a script similiar to the following:
--start-code--
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function window_onbeforeunload() {
return false;
}
//-->
</SCRIPT>
</HEAD>
<BODY LANGUAGE=javascript onbeforeunload="return window_onbeforeunload()">
<P> </P>
</BODY>
</HTML>
--end-code--
What this code attempts to do, is ask a user to confirm yes/no before they close the browser window. But the message is a little ugly.
The dialog is:
"Are you sure you want to navigate away from this page?
false
Press OK to Continue or Cancel to stay on the current page"
Now, what I am trying to do, is ask the user if they want to save their changes (to an HTML form) before closing the window. But I need a cleaner dialog than the one I am getting. (It is just going to confuse people)
Ideally the logic would be this...
User clicks to close window.
Dialog comes up asking user if they'd like to save changes.
If user clicks no, allow window to close.
If user clicks yes, cancel the window_close and call function saveChanges();
Can it be done? I don't mind using an HTA (HTML application) if it allows me to do it.
Cheers,
Dave.