Using window open to change existing window's location

  • Thread starter Bernd Liebermann
  • Start date
B

Bernd Liebermann

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
 
E

Erwin Moller

Bernd said:
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
 
B

Bernd Liebermann

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"
 
E

Erwin Moller

Bernd said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top