3 Replies Latest reply on Jul 5, 2010 6:04 AM by eswaramoorthy1985

    How to count 'opened newwindow' ?

    eswaramoorthy1985

      Hi,

       

          I want to count currently opened new windows and,  if any window closed, then show the currently opened new window count.

       

      Main page have two links for open new window( newwindow1, newwindow2) and  Get Window Count Button.

      New window have close link.

       

      If i have open 2 new window, then i calculate currently opened window.

      But, if any window i close using ( close link, or browser closewindow),  now only one new window is opened.

       

      Here i don't know, how to show the opened window count is 1.

       

      Totally 4 files are : MainPage.jsp , newwindow1.jsp , newwindow2.jsp and windowcount.js


      MainPage.jsp

       

      <f:view>
          <html>
              <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">            
                  <a4j:loadScript src = "windowcount.js" />
              </head>
              <body>                     
                      <h:outputLink value="#" onclick="window.open('newwindow1.jsp','firstwindow','width=600,height=600');addWindowCount();">
                          <h:outputText value="new Window1"/>
                      </h:outputLink>
       
                      <h:outputLink value="#" onclick="window.open('newwindow2.jsp','secondWindow','width=600,height=600');addWindowCount();">
                          <h:outputText value="New window 2"/>
                      </h:outputLink>                
      
                  <a4j:commandButton value="Get Window Count" onclick="getNewWindowCount();"/> 
                                           
              </body>
          </html>
      </f:view>
      
      

       

      newwindow1.jsp
      <f:view>
          <html>
              <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">           
                  <title>First Window</title>           
              </head>
              <body>          
                   <a4j:commandLink id="firstWindowCloseLinkId" 
                                    value="Close Window" 
                                    onclick="javascript:window.close()"/>            
              </body>
          </html>
      </f:view>
      

       

      newwindow2.jsp

      f:view>
          <html>
              <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">           
                  <title>Second Window</title>           
              </head>
              <body>          
                   <a4j:commandLink id="secondWindowCloseLinkId" 
                                    value="Close Window" 
                                    onclick="javascript:window.close()"/>            
              </body>
          </html>
      </f:view>
      
      
      
      
      windowcount.js
      var countNewWindow = 0;
      
      function addWindowCount()
      {
          countNewWindow++;
      }
      
      function getNewWindowCount()
      {    
          alert("Current opened NewWindow : " + countNewWindow);
      }
      


      So i want to write code for, when i close the opened newWindow , reduce the window count.
      May be i choose either closelink or browser close window.

      The newwindow have not only closelink, it have some fields.

      Help me.
      Thanks in advance.