1 Reply Latest reply on Jul 11, 2010 10:59 PM by Akaine Harga

    How to show the 'new tab closed' message, when i close new tab?

    Eswara MoorthyNEC Newbie

      Hi,

      I have one parent page and child page. the child page opened in new tab

      I want to show one alert message (The child page is closing), when i close the child tab.


      How to show the closing messgae, when close the tab? (If Refresh the child page, not show the closed message).

       

      I can detect the tab close event in IE and FireFox.

      Then i want to detect newtab close event in other browser (Not refreshing child page)

       

      Main.jsp

       

      <f:view>
          <html>
              <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">                        
              </head>
              <body>                                     
                     <h:outputLink value="child.jsp" target="_blank">
                            <h:outputText value="new Window1"/>
                     </h:outputLink>                      
              </body>
          </html>
      </f:view>
      
      
      

       

      child.jsp

      <f:view>
          <html>
              <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">             
                  <script type="text/javascript">
      
                  function doUnload()
                  {                    
                      if(navigator.userAgent.toLowerCase().indexOf("firefox") > 0)
                      {
                          var winWidth = document.body.clientWidth;
                          var winHeight = document.body.clientHeight;                   
                          if ((winWidth <= 0) || (winHeight <= 0) || (winWidth <= -80))
                          {
                            alert("Child Tab is closing in FF");                        
                          }
                      }
      
                      if(navigator.appName == "Microsoft Internet Explorer")
                      {
                          if ((window.event.clientX < 0) || (window.event.clientY < 0) || (window.event.clientX < -80))
                          {
                              alert("child tab is closing in IE");                        
                          }
                      }                                       
                  }
              </script>
           </head>
           <body onunload="doUnload()">                                                   
      
                    <h:outputText value="This is child page"/>                               
              </body>
          </html>
      </f:view>
      
      
      
      

       

       

      Here the message "Child tab is closing" in IE and FireFox, when i close the child page.(If Referesing the page not show the closing message).

       

      So i want to show close message for other browser( Google chrome, opera etc).

       

      Help me.

      Thanks for your effort.