2 Replies Latest reply on Jul 1, 2010 9:55 PM by Eswara MoorthyNEC

    How to share javascript variable for two different window?

    Eswara MoorthyNEC Newbie

      Hi,

       

      I have two jsp(one is main page, another one is new window) and single javascript file.

       

      MainPage and New Window have 'Test' , 'ClickedCount' buttons.

      First, I click 3 times in MainPage 'Test' button .  Then i open New Window.
      Now , i click  2 times in newWindow 'Test' button.
      So totally i clicked 5 times.

       

      Each time i click, i count the button click in javascript.

       

      But  mainwindow shows only 3 times, --> getTestButtonClickedCount()
      And new window shows only 2 times . --> getTestButtonClickedCount()

      Here i use same single javascript file (count.js)

       

      So how to get total clickCount both window (mainWindow + NewWindow) 'Test' button.

       

      MainWindow.jsp

      <f:view>
      <html>
           <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
                <script src="count.js" type="text/javascript"></script>
           </head>
      <body>
            <a4j:commandButton value = "Test"         onclick = "countTestButtonClick()"/>
            <a4j:commandButton value = "ClickedCount" onclick = "getTestButtonClickedCount();"/>
      
              <a4j:commandLink value = "Click to open NewWindow" 
                               onclick="window.open('NewWindow.jsp','newwindow',
                                       'width=400,height=200')"/>  
      </body>
      </html>
      </f:view>
      
      

       

      NewWindow.jsp

      <f:view>
      <html>
           <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
                <script src="count.js" type="text/javascript"></script>
           </head>
      <body>
            <a4j:commandButton value = "Test"         onclick = "countTestButtonClick()"/>
            <a4j:commandButton value = "ClickedCount" onclick = "getTestButtonClickedCount();"/>        
      </body>
      </html>
      </f:view>
      
      

      count.js

       

      var clickCount = 0;
      
      function countTestButtonClick()
      {    
          clickCount++;
      }
      
      function getTestButtonClickedCount()
      {
         alert("Total Number of clicked : " + clickCount);
      }
      
      

       

      Help me.

      Thanks in advance.