By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

Problem with window.top.

dmjpro
100+
P: 2,476
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="abc" value="  Copy 2 Clipboard" onclick="window.top.value=this.value;" />
  2. <a href="test.html" target="_blank">Open a new window!!!!</a>
  3. <input type="text" name="abc1" value="" onclick="this.value=typeof window.top.value!='undefined'?window.top.value:'';"/>
  4.  
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.
Jul 9 '08 #1
Share this Question
Share on Google+
13 Replies


dmjpro
100+
P: 2,476
I changed my code to ....

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

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Simple Test</title>
  6. <script type="text/javascript">
  7. window.top.test_value = null;
  8. function test_abc(){
  9.     window.top.test_value = "Debasis Jana....!!!!";
  10.     alert(window.top.test_value);
  11. }
  12.  
  13. function getTopVal(){
  14.     var tmp = window;
  15.     while(tmp.opener){
  16.         tmp = tmp.opener;
  17.     }
  18.     alert(tmp.top.value);
  19. }
  20. </script>
  21. </head>
  22. <body">
  23. <input type="button" name="abc" value="  Copy 2 Clipboard" onclick="window.top.value=this.value;" />
  24. <a href="test1.html" target="_blank">Open a new window!!!!</a>
  25. <input type="text" name="abc1" value="" onclick="getTopVal();"/>
  26. </body>
  27. </html>
  28.  
  29.  
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <script type="text/javascript">
  6. function getTopVal(){
  7.     var tmp = window;
  8.     while(tmp.opener){
  9.         tmp = tmp.opener;
  10.     }
  11.     alert(tmp.top.value);
  12. }
  13. </script>
  14. <title>Test!!!</title>
  15. </head>
  16.  
  17. <body>
  18. <input type="text" name="abc2" value="" onclick="getTopVal();"/>
  19. </body>
  20. </html>
  21.  
  22.  
Now it's working as i expected!
:-)
Jul 9 '08 #2

hsriat
Expert 100+
P: 1,654
What is this window.top.value?
Never heard about this.
Jul 9 '08 #3

acoder
Expert Mod 15k+
P: 16,027
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.
Jul 10 '08 #4

dmjpro
100+
P: 2,476
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
Jul 10 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Yes, window.test_value would have been enough. Then from the child windows, window.opener.test_value should give you the value you need.
Jul 10 '08 #6

dmjpro
100+
P: 2,476
Yes, window.test_value would have been enough. Then from the child windows, window.opener.test_value should give you the value you need.
Yeah that also be fine. :-)
Thanks Acoder!
Jul 10 '08 #7

acoder
Expert Mod 15k+
P: 16,027
No problem. You're welcome :)
Jul 10 '08 #8

dmjpro
100+
P: 2,476
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.
Jul 11 '08 #9

acoder
Expert Mod 15k+
P: 16,027
In that case, you could use window.top.test_value or top.opener.top.test_value (for frame in a popup window).
Jul 11 '08 #10

dmjpro
100+
P: 2,476
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.

Expand|Select|Wrap|Line Numbers
  1. function getTopVal(){
  2.     var tmp = window;
  3.     while(tmp.opener){
  4.         tmp = tmp.opener;
  5.     }
  6.     alert(tmp.top.value);
  7. }
  8.  
Anyway, Thanks for your help!
Jul 11 '08 #11

acoder
Expert Mod 15k+
P: 16,027
Yeah, I did see that, but I would avoid "value" because it can be confusing.
Jul 11 '08 #12

dmjpro
100+
P: 2,476
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
Jul 11 '08 #13

acoder
Expert Mod 15k+
P: 16,027
Yes, exactly! We finally got there ;)
Jul 11 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.