473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Global Variables Between Parent and Child Documents (Windows)

I have a library of functions representing a filesystem interface
(essentially a file selection interface, to be used in
opening/reading/writing/closing files).

Heavily scripted HTML document #1, very application-like, must include the
JS file for this library of functions. One reason is that it must call a
function to name a "callback" function, and within its own script block,
must define the callback function. The callback handles the selected file
name.

HTML document #2 is essentially a new document (window) created to present
the filesystem/file selection interface as dynamically updated HTML-
formatted tables of the list of file names/properties and subdirectory
names/properties of the current directory.

The problem is that the JS library file includes global variables which
are arrays to store the current directory file and subdirectory info. The
JS file is included through a <SCRIPT> element (as external JS file) in
both HTML documents #1 and #2. Document #2 is created through an open()
window call in Document #1.

The odd thing is: Document #2 creates the arrays in the defined global
variables, and then the array variables are accessed to build the HTML-
formatted tables during the initial creation of Document #2.

But when the user presses a button inside Document #2 to select a file or
folder in a table cell, the arrays are "undefined" ("void").

I am seeing this as a some sort of conflict of global variables between
documents #1 and #2. That is global variables in Document #1 (the parent
window/document) could be used to construct document #2, and then when
document #2 was intially constructed, its inherited global variables were
initialized (undefined globals are "voided").

I have been trying to find something in the JS/ECMA specification which
explains how this works and how to deal with this.

Sep 16 '05 #1
2 9128
Hello

AFAIK, everytime you include a script into a document, new instances of
these variables will be present for that document.
So if you include two JS scripts into two different documents, then each
will have his own copy of global variables.

One way to access global variables between window and opener is to
centralize the location of the global variables and access them
appropriately.

Example:

doc1:
var v1 = 1, v2 = 2;

var w = window.open('doc2.htm', 'doc2');

doc2:

To access v1 and v2 global variables, you have to reach doc1's window
appropriately, and in that case, from doc2:

alert(window.opener.window.v1);
hope that helps,
Elias

"Patient Guy" <Pa*********@nowhere.to.be.found.com> wrote in message
news:Xn******************@207.115.17.102...
I have a library of functions representing a filesystem interface
(essentially a file selection interface, to be used in
opening/reading/writing/closing files).

Heavily scripted HTML document #1, very application-like, must include the
JS file for this library of functions. One reason is that it must call a
function to name a "callback" function, and within its own script block,
must define the callback function. The callback handles the selected file
name.

HTML document #2 is essentially a new document (window) created to present
the filesystem/file selection interface as dynamically updated HTML-
formatted tables of the list of file names/properties and subdirectory
names/properties of the current directory.

The problem is that the JS library file includes global variables which
are arrays to store the current directory file and subdirectory info. The
JS file is included through a <SCRIPT> element (as external JS file) in
both HTML documents #1 and #2. Document #2 is created through an open()
window call in Document #1.

The odd thing is: Document #2 creates the arrays in the defined global
variables, and then the array variables are accessed to build the HTML-
formatted tables during the initial creation of Document #2.

But when the user presses a button inside Document #2 to select a file or
folder in a table cell, the arrays are "undefined" ("void").

I am seeing this as a some sort of conflict of global variables between
documents #1 and #2. That is global variables in Document #1 (the parent
window/document) could be used to construct document #2, and then when
document #2 was intially constructed, its inherited global variables were
initialized (undefined globals are "voided").

I have been trying to find something in the JS/ECMA specification which
explains how this works and how to deal with this.

Sep 16 '05 #2

"lallous" <la*****@lgwm.org> wrote in message
news:3o************@individual.net...
Hello

AFAIK, everytime you include a script into a document, new instances of
these variables will be present for that document.
So if you include two JS scripts into two different documents, then each
will have his own copy of global variables.

One way to access global variables between window and opener is to
centralize the location of the global variables and access them
appropriately.

Example:

doc1:
var v1 = 1, v2 = 2;

var w = window.open('doc2.htm', 'doc2');

doc2:

To access v1 and v2 global variables, you have to reach doc1's window
appropriately, and in that case, from doc2:

alert(window.opener.window.v1);
hope that helps,
Elias


this is exactly what I was going to say.

Include all the global vars in the parent scripts and have the child page
reference them there.
Sep 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MrEntropy | last post by:
Greetings, I'm having a little trouble getting an idea running. I am writing a C program which is really a frontend to a Python program. Now, my C program starts up, does some initialisation like...
2
by: Rustam Asgarov | last post by:
how can i access variables defined in the parent class from the child class: By some way other than passing as parameter to constructor. I mean. class Parent{ public int b; public...
5
by: Viper | last post by:
.... say, like MS Word opens another instance of himself when you open another document. If you close the first 'Word', the second document remains alive. I can't figure out how to do the same...
3
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI...
2
by: Chuck | last post by:
Does the Global.asax from a parent application run for a child application? Is there a way to configure this to happen? Scenario: Site A has a parent: Site B User goes from a page in site A...
1
by: Raed Sawalha | last post by:
I have Solution with multiple project as following hierarchy Parent Child Child Child the parent is the ONLY one has the Global.ascx , now im in case i need to access the global.ascx public...
3
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can...
10
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public...
0
by: Iain | last post by:
Hi All My apologies for posting this here but the Delphi newsgroup is very slow. Using Borland Developer Studio 2006 - creating a C# .net application. I have a datagrid (id = "Documents")...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.