Method invocation betwee windows.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bowen Simmons

    #1

    Method invocation betwee windows.

    OK. I have a test html page:

    "To.html":

    <html>
    <head>
    <title>To</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <script language="JavaS cript">
    function Go(aString)
    {
    alert(aString);
    return false;
    }
    </script>
    </head>
    <body>
    <a href="" id="T1" onclick="return window.Go(id);" > <p>T1
    anchor</p></a>
    <a href="" id ="T2" onclick="return window.Go(id);" > <p>T2
    anchor</p></a>
    </body>
    </html>
    </html>

    If I press on either the "T1" or the "T2" link, it brings up an alert
    with the text set to either "T1" or "T2". Life is good so far.

    Now, I use a second window to open the page:

    "From.html"

    <html>
    <head>
    <title>From</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <script language="JavaS cript">
    function Go(aString)
    {
    var vMapWindow = window.open("To .html", "CurrentMap ");
    vMapWindow.focu s();
    vMapWindow.Go(a String);
    return false;
    }
    </script>
    </head>
    <body >
    <a href="T1" id="T1" onclick="return window.Go(id)"> <p>T1
    anchor</p></a>
    <a href="T2" id="T2" onclick="return window.Go(id)"> <p>T2
    anchor</p></a>
    </body>
    </html>

    When I press either the "T1" or "T2" links on the "From.html" page,
    what is supposed to happen is that the browser is supposed to open a
    new window showing "To.html" (which it does), give it the focus (which
    it does even without the focus() call, but as I understand it browsers
    are not consistent here), and then call the Go() method in the new
    window showing "To.html" which should bring up the alert. It doesn't
    do this however. In fact, it seems to throw an exception instead,
    causing the "From.html" window to attempt to navigate to the
    non-existent "T1" or "T2" page.

    I am testing this with Safari, but have also tried Firefox and even
    old Mac IE 5, and all of them fail the same way so I assume this is
    not a browser problem, but a mistake on my part. Anybody know what my
    mistake is?
  • Lee

    #2
    Re: Method invocation betwee windows.

    Bowen Simmons said:
    [color=blue]
    > function Go(aString)
    > {
    > var vMapWindow = window.open("To .html", "CurrentMap ");
    > vMapWindow.focu s();
    > vMapWindow.Go(a String);
    > return false;
    > }
    ></script>[/color]

    The window.open() method returns without waiting for the window to
    actually be opened, so at the time that you're trying to invoke
    the Go() method in the new window, it doesn't exist yet.

    You can confirm this by making vMapWindow a global variable and
    adding a third link that invokes vMapWindow.Go(' T3'). Push one
    of your links to create the window, then wait for the window to
    completely open and press the new link. It will work.

    Comment

    Working...