|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
I try to loop through all the variables of a parent window using a "for in" loop:
for(i in parent) document.writeln(i+'<br>'); According to my JS docs this should return all the properties of the parent window - and it does, but without any of it's variables. I thought that all globally defined variables automatically become properties of the window object. Look at this: a=1; window.b=2; document.writeln(a); document.writeln(b); document.writeln(window.a); document.writeln(window.b); Output: 1212 But the for-in-loop only returns b, and NOT a if I place the second code block in the parent. Any ideas how I can scan through my parent's variables without defining them all with a "window." prefix? ___ Jpsy |
|
#2
|
|||
|
|||
|
Well - I just found the answer to the behaviour of the for-in-loop.
From http://www.chinalinuxpub.com/doc/oreillybookself/web/jscript/ch05_06.htm : The for/in loop does not actually loop through all possible properties of all objects. The rules below specify exactly which properties the statement does list and which it does not in Navigator 3.0. Internet Explorer may use somewhat different rules:Still I am searching for another way to find all variables by some peace of code. Maybe a false hope... ____ Jpsy |
|
#3
|
|||
|
|||
|
Hello there, I was actually trying to find such a solution for IE... Any success so far?
I need to duplicate a window in a statefull way... Here's my code, works only for Mozilla and opera: function doThatThing2() { var dup = open(); var elements = {}; // Excluding standard windows attributes of a virgin window and functions... for (var k in window) { if(!(k in dup) && typeof(window[k]) != 'function'){ elements[k] = window[k]; } } dup.document.open() dup.document.write(window.document.documentElement .innerHTML); for (var n in elements) { dup[n] = elements[n]; // debug... alert(n + " : " + elements[n] + " : " + dup[n]); } dup.document.close(); } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Looping through all of a windows variables with "for in" |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|