Pop up on Browser close event

Last post 05-22-2008 12:54 PM by NC01. 4 replies.

Sort Posts:

  • Pop up on Browser close event

    05-19-2008, 6:16 PM
    • Member
      3 point Member
    • ken_rgr
    • Member since 10-31-2007, 9:53 PM
    • Posts 48

    Hi Guys

    In my project I need to popup a window when user closes the browser.

    I need to show the popup window only when the user clicks on (x) button of the browser(Top right).

    Popup should not show in other unload events.

    Any help will be appreciated.

     Thanks in advance.

  • Re: Pop up on Browser close event

    05-19-2008, 11:43 PM
    • All-Star
      20,674 point All-Star
    • A1ien51
    • Member since 05-06-2005, 6:46 PM
    • MD USA
    • Posts 3,803
    You have not been able to perform this action for a long time now in browsers since they have pop up blockers installed. Plus there is no way to really tell if the user closed the window with the X. There is some x/ positioing hack in some browsers, but that is a limited number . Plus there are other ways to close the window other than the X. Best bet is to use onbeforeunload and code the application to understand the difference between a postback and closing the browser through some boolean flags.

    Eric
  • Re: Pop up on Browser close event

    05-22-2008, 2:44 AM
    Answer
    • Participant
      1,092 point Participant
    • blodfox777
    • Member since 07-12-2007, 12:30 PM
    • Posts 159

    Hi

    try the following code, I have tested in IE 6/7 

    Enjoy the code~ 

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function window.onbeforeunload()   
    {   
        if( event.clientX>document.body.clientWidth && event.clientY<0 || event.altKey )   
        {   
            window.event.returnValue="are you sure to exit?";   
        }
    }
    //-->
    </SCRIPT>
     
    Regards!

    -- "Mark As Answer" If my reply helped you --
  • Re: Pop up on Browser close event

    05-22-2008, 11:33 AM
    • Member
      3 point Member
    • ken_rgr
    • Member since 10-31-2007, 9:53 PM
    • Posts 48

    Hi BoldFox777

    its working perfectly for Internet Explorer.

    Is it possible can you get me some code that works for Fair fox also.

    Thanks for your help.

     

  • Re: Pop up on Browser close event

    05-22-2008, 12:54 PM
    Answer
    • All-Star
      76,257 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,209

    Try this:

    if ( window.event )
    {
     window.event.returnValue = 'Are you sure you want to exit?';
    }
    else
    {
     return 'Are you sure you want to exit?';
    }

    NC...

     

Page 1 of 1 (5 items)