JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old March 4th, 2004, 05:32 AM
Jpsy Jpsy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 Jpsy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Looping through all of a windows variables with "for in"

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

Reply With Quote
  #2  
Old March 4th, 2004, 06:15 AM
Jpsy Jpsy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 Jpsy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
  • ...
  • ...
  • It does not list object properties or methods implicitly defined in an object with the var or function keywords. (In client-side JavaScript, defining a variable with var is the same as defining a property of the same name in the current Window object, except for the different treatment of these two cases by the for/in loop.) Properties implicitly defined by the var keyword at any time will never again be listed, even if the property is afterwards directly and explicitly set in the object. This last is not true for the function keyword.
Still I am searching for another way to find all variables by some peace of code. Maybe a false hope...
____
Jpsy

Reply With Quote
  #3  
Old May 12th, 2004, 10:06 AM
Jeffer Jeffer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 Jeffer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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();
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Looping through all of a windows variables with "for in"


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway