Bassie Bassie - 1 year ago 96
Javascript Question

How to Exit Programatically Created Browser in JScript

I have the following

which opens Internet Explorer, navigates to the current users' Lync Response Group Settings page, and clicks on one of the checkboxes found there:

var ie = WSH.CreateObject('InternetExplorer.Application');
url = "",

ie.visible = true;
while (ie.readyState != 4) WSH.Sleep(25);


Once this is done, I want the script to close the browser window.

I tried the following:


But got this error:

Object doesn't support this property or method

Answer Source

TLDR: Use ie.Quit().

This has nothing to do with VBScript vs. JScript. What you call "the JavaScript close command" is the DOM (not JS) method (not "command") of the Window object. Usually the DOM is the thing you manipulate with JS code that runs inside the browser as part of the HTML it's displaying.

This is unrelated to the InternetExplorer automation object. This method describes the Internet Explorer program, not the HTML page that is displayed in it right now. For example, it has a property that controls whether or not you're in "Offline browsing" mode. That's not part of the DOM.

This object has a bunch of other methods and properties which are mostly documented in the MSDN page I linked above - InternetExplorer object. Specifically, it implements the IWebBrowser2 interface which means it implements the IWebBrowser2::Quit method.

Which is, obviously, unrelated to the WSH WScript.Quit(errorCode) method. Their signatures aren't even compatible. The WSH method returns an (optional) error code, the IE method doesn't.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download