Microsoft KB Archive/244375

= BUG: Window.Closed Property Fails in WebBrowser Control =

Article ID: 244375

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0

-



This article was previously published under Q244375



SYMPTOMS
A Web page hosted in a WebBrowser control may encounter the following runtime error when attempting to use the window.closed property:

The remote server machine does not exist or is unavailable

This error occurs only when there is no other instance of Internet Explorer running. It works fine if an instance of Internet Explorer is launched, before running the application that hosts the WebBrowser control.



RESOLUTION
If the WebBrowser control application handles the NewWindow2 event to create new browser windows, no error occurs, but the window.closed property always returns false.

There is no way to return a valid result with the window.closed property in WebBrowser applications that manage new windows via NewWindow2. The best resolution is to alter the Web page script on the closing window to notify the opener window when it is closing. This can be done in the onUnload event of the window object. The opener window can be reached through the opener property. Here is a JavaScript example:  // variable WindowClosed has been defined at global scope in the // opening page. This page will now check WindowClosed instead of // "window.closed" to see if the opened window is still around window.opener.WindowClosed = true;   window.opener.WindowClosed = false;  WebBrowser applications that do not handle the NewWindow2 event can catch the runtime error in client script using javascript exception handling or "On Error Resume Next" in VBScript. Here is a JavaScript example: try {     bClosed = otherwin.closed; }  catch(e) {     alert("The Other Window is Currently Closed (exception thrown)"); return; }  if (bClosed) {      alert("The Other Window is Currently Closed"); }  else {      alert("The Other Window is Currently Open"); } NOTE: Javascript exception handling requires version 5.0 of the JScript engine, which ships with Internet Explorer 5.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

