Using window open to change existing window's location

Discussion in 'Javascript' started by Bernd Liebermann, Feb 8, 2004.

  1. Hi,

    I'm trying to change the content of an existing window from a second window
    using window.open(). This works fine in Netscape 7, but IE 6.0 returns an
    error, saying there's an invalid parameter. If I omit the target window's
    name, everything works fine except that my document is opened in a new
    window.

    window.open("somescript.php", "existing_target_window");

    Can anybody see what's wrong with that?

    Thanks,
    Bernd
     
    Bernd Liebermann, Feb 8, 2004
    #1
    1. Advertising

  2. Bernd Liebermann

    Erwin Moller Guest

    Bernd Liebermann wrote:

    > Hi,
    >
    > I'm trying to change the content of an existing window from a second
    > window using window.open(). This works fine in Netscape 7, but IE 6.0
    > returns an error, saying there's an invalid parameter. If I omit the
    > target window's name, everything works fine except that my document is
    > opened in a new window.
    >
    > window.open("somescript.php", "existing_target_window");
    >
    > Can anybody see what's wrong with that?
    >
    > Thanks,
    > Bernd


    Hi,

    Do it like this:

    var myOtherWin;

    if (myOtherWin) {
    // already is open
    myOtherWin.location="blabla.php";
    } else {
    // create it
    myOtherWin = window.open("somescript.php", "existing_target_window");
    }

    So the trick is to keep a reference to that window.

    Regards,
    Erwin Moller
     
    Erwin Moller, Feb 9, 2004
    #2
    1. Advertising

  3. Erwin,

    the problem ist that my second window has been opened by the first, so I
    don't know how to get a reference to the first that I could use in the
    second as there is no global windows collection. Any further ideas?

    Thanks,
    Bernd Liebermann

    "Erwin Moller"
    <> schrieb im
    Newsbeitrag news:40277e97$0$150$4all.nl...
    > Bernd Liebermann wrote:
    >
    > > Hi,
    > >
    > > I'm trying to change the content of an existing window from a second
    > > window using window.open(). This works fine in Netscape 7, but IE 6.0
    > > returns an error, saying there's an invalid parameter. If I omit the
    > > target window's name, everything works fine except that my document is
    > > opened in a new window.
    > >
    > > window.open("somescript.php", "existing_target_window");
    > >
    > > Can anybody see what's wrong with that?
    > >
    > > Thanks,
    > > Bernd

    >
    > Hi,
    >
    > Do it like this:
    >
    > var myOtherWin;
    >
    > if (myOtherWin) {
    > // already is open
    > myOtherWin.location="blabla.php";
    > } else {
    > // create it
    > myOtherWin = window.open("somescript.php", "existing_target_window");
    > }
    >
    > So the trick is to keep a reference to that window.
    >
    > Regards,
    > Erwin Moller
    >
     
    Bernd Liebermann, Feb 11, 2004
    #3
  4. Bernd Liebermann

    Erwin Moller Guest

    Bernd Liebermann wrote:

    > Erwin,
    >
    > the problem ist that my second window has been opened by the first, so I
    > don't know how to get a reference to the first that I could use in the
    > second as there is no global windows collection. Any further ideas?
    >
    > Thanks,


    Hi Bernd,

    try 'opener'

    opener holds a reference to the window that opened the one that is using
    opener.

    so:
    win1 opens win2
    from win2 you get a reference to win1 by:

    opener.document.location="Doughlas_Adams.html";

    There are a few securityrestrictions: if the content in win1 and win2
    originate from different domains, some browsers will block cross-window
    javascript.

    Good luck!

    Regards,
    Erwin
     
    Erwin Moller, Feb 11, 2004
    #4
    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. nrm
    Replies:
    3
    Views:
    534
  2. Replies:
    0
    Views:
    190
  3. Ben
    Replies:
    0
    Views:
    122
  4. saiho.yuen
    Replies:
    3
    Views:
    434
    kaeli
    Sep 14, 2004
  5. xhe
    Replies:
    1
    Views:
    127
    Randy Webb
    Feb 9, 2007
Loading...

Share This Page