Problem with window.top.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Problem with window.top.

    [code=html]
    <input type="button" name="abc" value=" Copy 2 Clipboard" onclick="window .top.value=this .value;" />
    <a href="test.html " target="_blank" >Open a new window!!!!</a>
    <input type="text" name="abc1" value="" onclick="this.v alue=typeof window.top.valu e!='undefined'? window.top.valu e:'';"/>
    [/code]

    Now i m opening the same page at a different window.
    There if i click on the text box then i m getting the undefined value of top.value
    Why it's happening?
    can't i get the [b]top.value[b] from any children window of that top window?
    Where i am wrong?

    Debasis Jana.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    I changed my code to ....

    I have my two source codes.
    those are given below!

    [code=HTML]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Simple Test</title>
    <script type="text/javascript">
    window.top.test _value = null;
    function test_abc(){
    window.top.test _value = "Debasis Jana....!!!!";
    alert(window.to p.test_value);
    }

    function getTopVal(){
    var tmp = window;
    while(tmp.opene r){
    tmp = tmp.opener;
    }
    alert(tmp.top.v alue);
    }
    </script>
    </head>
    <body">
    <input type="button" name="abc" value=" Copy 2 Clipboard" onclick="window .top.value=this .value;" />
    <a href="test1.htm l" target="_blank" >Open a new window!!!!</a>
    <input type="text" name="abc1" value="" onclick="getTop Val();"/>
    </body>
    </html>

    [/code]

    [code=HTML]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    function getTopVal(){
    var tmp = window;
    while(tmp.opene r){
    tmp = tmp.opener;
    }
    alert(tmp.top.v alue);
    }
    </script>
    <title>Test!! !</title>
    </head>

    <body>
    <input type="text" name="abc2" value="" onclick="getTop Val();"/>
    </body>
    </html>

    [/code]

    Now it's working as i expected!
    :-)

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      What is this window.top.value?
      Never heard about this.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Not sure what you were trying to do. window.top usually refers to the top frame. If you wanted to set a value, you could have set a global variable.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by acoder
          Not sure what you were trying to do. window.top usually refers to the top frame. If you wanted to set a value, you could have set a global variable.
          See what i am trying to do i want to save a value some where and i want to make available this value to any children window of that window.
          So i thought it's better to save in top window's reference.
          Anyway i can also save in that window's reference.
          Anyway by this experiment i came to know the actual reality of top. :-)

          Debasis Jana

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Yes, window.test_val ue would have been enough. Then from the child windows, window.opener.t est_value should give you the value you need.

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by acoder
              Yes, window.test_val ue would have been enough. Then from the child windows, window.opener.t est_value should give you the value you need.
              Yeah that also be fine. :-)
              Thanks Acoder!

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                No problem. You're welcome :)

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by acoder
                  No problem. You're welcome :)
                  Thanks again!!
                  Sorry Acoder I forgot to mention one thing that in my case there is no way rather than using top.
                  Actually i want to save the value from a window which can be at any frame of the main window. And the child window may be from another frame of the main window.
                  So here is only option is top.

                  Debasis Jana.

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    In that case, you could use window.top.test _value or top.opener.top. test_value (for frame in a popup window).

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Originally posted by acoder
                      In that case, you could use window.top.test _value or top.opener.top. test_value (for frame in a popup window).
                      Yeah that's what i m using top ..and i already found the solution.
                      i am using this function to find out that value.

                      [code=JAVASCRIPT]
                      function getTopVal(){
                      var tmp = window;
                      while(tmp.opene r){
                      tmp = tmp.opener;
                      }
                      alert(tmp.top.v alue);
                      }
                      [/code]

                      Anyway, Thanks for your help!

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Yeah, I did see that, but I would avoid "value" because it can be confusing.

                        Comment

                        • dmjpro
                          Top Contributor
                          • Jan 2007
                          • 2476

                          #13
                          Originally posted by acoder
                          Yeah, I did see that, but I would avoid "value" because it can be confusing.
                          Ohh...!!!
                          That's what you were saying.....test _value.
                          lolz!

                          Debasis Jana

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Yes, exactly! We finally got there ;)

                            Comment

                            Working...