window.onbeforeunload

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tecknick
    New Member
    • Apr 2006
    • 1

    window.onbeforeunload

    Hi All

    I am using the window.onbefore unload event on a webpage as follows :

    Code:
    window.onbeforeunload = confirmExit;
    
    function confirmExit()
      {
        if (changesMade == 1 && needToConfirm)
            {
            return "You have not saved changes on this page";
            }
      }
    The function returns a prompt to the user correctly.

    If the user clicks "OK" on the dialog, the page exits correctly. However I would like to know if the user clicks "Cancel" .

    The reason behind this is that I have a animated gif which appears on the unloading of a window and if the user clicks "Cancel" which stops the unload I would like to hide the animated gif.

    Does anyone know how to determine if the "Cancel" button on the onbeforeunload dialog has been selected?

    Thank you in advance.

    Tecknick
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    There's no proper method of determining if Cancel has been clicked.

    You can try using a timeout and cancelling onunload, but it may not work reliably.

    Comment

    Working...