Show alert on browser close but don't show alert while closing from logoff

Posted by Neha Jain on Stack Overflow See other posts from Stack Overflow or by Neha Jain
Published on 2012-11-23T04:45:01Z Indexed on 2012/11/23 4:59 UTC
Read the original article Hit count: 371

Filed under:
|

In my application when user logs out the browser is closed. And on browser close I am throwing an alert. Now what I want is if I directly close the browser window alert should come but if window is closed through logout alert should not come as I have shown another confirm message of logout.

                  function closeEditorWarning(){

     for (var i=0;i<childWindow.length;i++) {
           if (childWindow[i] && !childWindow[i].closed) childWindow[i].close();
                if(i==0)
                   {
                 alert("This will close all open e-App applications");
                 }

                     }

        window.close();  

                       }


              window.onbeforeunload = closeEditorWarning;

And this is my logout code

              $('#'+id).click(function(event){
                        event.preventDefault();
                                                $('#centerContent').load('<%=request.getContextPath()%>/'+target);
                    });
                }   
                else 
                {
                $('#'+id).click(function(event){

                        event.preventDefault();
                        var r=confirm("logout");
                       if (r==true)
                       {
                           flag=true;


                              for (var i=0;i<childWindow.length;i++) {
                                    if (childWindow[i] && !childWindow[i].closed)
                                        childWindow[i].close();
                                  } 

                             window.close();
                             }
                      else
                         {
                         }
                    });
                }

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery