Kevin Ar18
07-24-2002, 07:07 PM
I have been using the following script to ask the user if they wanted to close the window. So far it has worked great.
<script language="JavaScript" event="onbeforeunload()" for="window">
if(mapSaved) {event.returnValue = "Exit the Map Editor?";}
else {event.returnValue = "You have not saved your map.\nAre you sure you want to exit the Map Editor?";}
</script>
However, I now would like to add something in. If the user decides to leave, I would like to run a script (aka submit a form) just before it closes.
Can anyone come up with a way to do this and still have that confirmation message come up?
I tried the following code, but it didn't submit the form and also gave me the confirmation message twice:
<script language="JavaScript" event="onunload()" for="window">
document.closeserver.submit();
</script>
<script language="JavaScript" event="onbeforeunload()" for="window">
if(mapSaved) {event.returnValue = "Exit the Map Editor?";}
else {event.returnValue = "You have not saved your map.\nAre you sure you want to exit the Map Editor?";}
</script>
However, I now would like to add something in. If the user decides to leave, I would like to run a script (aka submit a form) just before it closes.
Can anyone come up with a way to do this and still have that confirmation message come up?
I tried the following code, but it didn't submit the form and also gave me the confirmation message twice:
<script language="JavaScript" event="onunload()" for="window">
document.closeserver.submit();
</script>