Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    GA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Confirm closing window and run script on close.

    I have been using the following script to ask the user if they wanted to close the window. So far it has worked great.

    PHP Code:
    <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:
    PHP Code:
    <script language="JavaScript" event="onunload()" for="window">
      
    document.closeserver.submit();
    </script> 

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer Check this out...


  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    GA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the info.
    From reading it, I didn't find any ways to do exactly what I needed.

    However, I got close.
    Here's what I tried (problem is it submits the form whether they chose OK or Cancel.
    PHP Code:
    <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?";}
      
    document.closeserver.submit();
    </script> 
    So, any ideas?

    BTW, thanks for the URL.

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onunload script

    Here is an idea...

    You could set a flag in the onbeforeunload

    based on that flag value decide whether or not to call the routine for the form submission.

    Hope that helps!

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    GA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do you mean by setting a flag?

  • #6
    New Coder
    Join Date
    Jul 2002
    Location
    GA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, found out what a flag was. We seem to both be on the same track. I was just trying to do that. However, I don't know how to get a value from the confirm message based on whether they chose OK, or Cancel and there lies the problem. So I guess the questions is, how can I determine if they chose OK or if they chose Cancel?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •