Global Variables Between Parent and Child Documents (Windows)

Discussion in 'Javascript' started by Patient Guy, Sep 16, 2005.

  1. Patient Guy

    Patient Guy Guest

    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.
     
    Patient Guy, Sep 16, 2005
    #1
    1. Advertising

  2. Patient Guy

    lallous Guest

    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" <> wrote in message
    news:Xns96D35E465143CUVAA@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.
    >
     
    lallous, Sep 16, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,134
    David Schwartz
    Dec 9, 2003
  2. Noel Dolan
    Replies:
    0
    Views:
    238
    Noel Dolan
    Jul 18, 2004
  3. orion30
    Replies:
    2
    Views:
    100
  4. Replies:
    2
    Views:
    173
    Richard Cornford
    Aug 27, 2007
  5. Bitswapper
    Replies:
    5
    Views:
    150
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page