Passing a JavaScript variable/object reference from one page to another?...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Davide Bruzzone

    Passing a JavaScript variable/object reference from one page to another?...

    Greetings all...

    Here's a description of the problem that I'm trying to solve:

    - I have a Web page from which users can open one or more other
    windows.
    - From that web page, the user can then select another part of the
    application thereby loading a different page into the original browser
    window (from which one or more "child" windows may have been opened).
    - When the user logs out of the application, regardless of whether
    they are on the page on which they started (in the original window),
    or they are in another part of the application, we need to be able to
    close all the windows that the user opened from the original window.

    We're using IE 6.0...

    My problem is that I can't find a way to pass the object that points
    to a window that was opened on one page into another page...

    For example:

    - I start out on a.html
    - I open a window... My code looks something like this:

    var myWindow = window.open(...

    - In the original browser window (which is currently displaying
    a.html) I click a link that takes me to b.html
    - In b.html I may need to close myWindow, but I don't have a reference
    to it, so I can't call myWindow.close( )

    Is there any way to pass the myWindow object into b.html (or to store
    it in some "global" area from which it can be accessed by any page)?
    Either that, or am I missing something far more obvious?

    I've started thinking about a number of solutions to this problem, but
    none of them are anywhere near elegant...

    Any suggestions would be greatly appreciated...

    Cheers...

    Dave Bruzzone
  • Greg

    #2
    Re: Passing a JavaScript variable/object reference from one page to another?...

    dbruzzone@attbi .com (Davide Bruzzone) wrote in message news:<7f16a340. 0307250953.3984 7e7f@posting.go ogle.com>...[color=blue]
    > Greetings all...
    >
    > Here's a description of the problem that I'm trying to solve:
    >
    > - I have a Web page from which users can open one or more other
    > windows.
    > - From that web page, the user can then select another part of the
    > application thereby loading a different page into the original browser
    > window (from which one or more "child" windows may have been opened).
    > - When the user logs out of the application, regardless of whether
    > they are on the page on which they started (in the original window),
    > or they are in another part of the application, we need to be able to
    > close all the windows that the user opened from the original window.
    >
    > We're using IE 6.0...
    >
    > My problem is that I can't find a way to pass the object that points
    > to a window that was opened on one page into another page...
    >
    > For example:
    >
    > - I start out on a.html
    > - I open a window... My code looks something like this:
    >
    > var myWindow = window.open(...
    >
    > - In the original browser window (which is currently displaying
    > a.html) I click a link that takes me to b.html
    > - In b.html I may need to close myWindow, but I don't have a reference
    > to it, so I can't call myWindow.close( )
    >
    > Is there any way to pass the myWindow object into b.html (or to store
    > it in some "global" area from which it can be accessed by any page)?
    > Either that, or am I missing something far more obvious?
    >
    > I've started thinking about a number of solutions to this problem, but
    > none of them are anywhere near elegant...
    >
    > Any suggestions would be greatly appreciated...
    >
    > Cheers...
    >
    > Dave Bruzzone[/color]


    I'm no expert, but my quick test seems to suggest that user defined
    properties of the window become undefined when the document changes.
    However, the built-in properties do not. So, say the original window
    document source looked like

    <script type='text/javascript'>
    function openIt(){
    opener = open('child.htm ','child', 'height=200,wid th=200');
    }
    </script>
    <title>A</title>
    <a href='b.htm'>b</a>
    <br>
    <button onclick='openIt ();'>openIt()</button>

    And the child window document:

    <title>Child</title>
    Child window

    And the second document:

    <script type='text/javascript'>
    function closeIt(){
    opener.close();
    }
    </script>
    <title>B</title>
    <button onclick='closeI t();'>closeIt() </button>

    My test (IE6) shows that the value of the opener property survives the
    document change, so the closeIt() function created by the second
    document closes the child window.

    As I said, I'm strictly a dabbler, so FWIW.

    Comment

    • Davide Bruzzone

      #3
      Re: Passing a JavaScript variable/object reference from one page to another?...

      gdsafford@hotma il.com (Greg) wrote in message news:<a8f367ed. 0307311524.4ce8 cea1@posting.go ogle.com>...
      [color=blue]
      > I'm no expert, but my quick test seems to suggest that user defined
      > properties of the window become undefined when the document changes.
      > However, the built-in properties do not. So, say the original window
      > document source looked like
      >
      > <script type='text/javascript'>
      > function openIt(){
      > opener = open('child.htm ','child', 'height=200,wid th=200');
      > }
      > </script>
      > <title>A</title>
      > <a href='b.htm'>b</a>
      > <br>
      > <button onclick='openIt ();'>openIt()</button>
      >
      > And the child window document:
      >
      > <title>Child</title>
      > Child window
      >
      > And the second document:
      >
      > <script type='text/javascript'>
      > function closeIt(){
      > opener.close();
      > }
      > </script>
      > <title>B</title>
      > <button onclick='closeI t();'>closeIt() </button>
      >
      > My test (IE6) shows that the value of the opener property survives the
      > document change, so the closeIt() function created by the second
      > document closes the child window.
      >
      > As I said, I'm strictly a dabbler, so FWIW.[/color]

      That's exactly what I was looking for! Thank you!

      Dave

      Comment

      Working...