Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error When 2nd Window Closed

Status
Not open for further replies.

clarkmurray

IS-IT--Management
Nov 9, 2002
35
US
I need to either open a second window or reload the 2nd window if it is already open, so I'm using the code:

function openmovie(url) {
if (!moviewin.open) {
moviewin = window.open("Window_2.htm",url,"");
moviewin.focus();
}
else {
moviewin.window.name = url;
moviewin.location.reload();
moviewin.focus();
}
}

This works just fine the first time the 2nd window is opened and if the 2nd window stays open. However, if the user closes the 2nd window, the next attempt at opening the window produces the error (in IE6) "The remote machince server does not exist or is unavailable".

Can someone tell me how to fix this?
 
try declaring "moviewin" as a global var outside of your function:
[tt]
// declare global var
var moviewin;

function openmovie(url) {
if (!moviewin.open) {
moviewin = window.open("Window_2.htm",url,"");
moviewin.focus();
}
else {
moviewin.window.name = url;
moviewin.location.reload();
moviewin.focus();
}
}
[/tt] =========================================================
if (!succeed) try();
-jeff
 
Not quite, but close. I still received an error, this time: "moviewin is null or not a object". But what you said did give me an idea of how to solve the problem so I just used:

var moviewin="";
function openmovie(url) {
if (moviewin == "" || moviewin.closed) {
...

Works fine now. Thanks for your suggestion.
 
clarkmurray,

yes, actually the best way to check for existence is this:

if (moviewin && moviewin.open && !moviewin.closed) {
// already open, so focus the window
moviewin.focus();
}
else {
// not open, so open it
...
}
=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top