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
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    window.onbeforeload executes twice???

    I want to use the below code to warn users that they are leaving the web form and to confirm they have saved their work. When I try the below and click the google link to leave the page I have to click through the dialog box twice. Why is that and how can I just get it the appear only once? I see if the user attempts to close the window the script works great but if the user attempts to click a link on the page they have to click through the dialoog box twwice. Please help.



    Code:
    <script type="text/javascript">
    
    
    function goodbye(e) {
    	if(!e) e = window.event;
    	//e.cancelBubble is supported by IE - this will kill the bubbling process.
    	e.cancelBubble = true;
    	e.returnValue = 'Have you saved your work? You sure you want to leave?'; //This is displayed on the dialog
    
    	//e.stopPropagation works in Firefox.
    	if (e.stopPropagation) {
    		e.stopPropagation();
    		e.preventDefault();
    	}
    }
    
    
    window.onbeforeunload=goodbye;
    
    </script>
     
        <a href="www.google.com">google</a>
    Last edited by nikko50; 10-12-2011 at 04:16 PM.

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Can you show a live example? In the code you posted, I don't see that dialog box you are talking about at all.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Quote Originally Posted by venegal View Post
    Can you show a live example? In the code you posted, I don't see that dialog box you are talking about at all.
    Right . A live example shows me the expected
    results of that code while opening the
    page from my file system gives me the result
    described in O.P.

  • #4
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    I only need this to function in ie. Can anyone help? Tracy

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    For me, this one executes only once:
    Code:
    window.onbeforeunload = function(e){
    var message = 'Have you saved your work? You sure you want to leave?';
    e=e||window.event; 
    e.returnValue = message;
    return message;
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Which browsers are you testing in (include which versions)? Does the double activation happen in all of them?


  •  

    Posting Permissions

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