Thursday, July 08, 2010

IE8 close tab programmatically

Sometimes you may wish to close a browser instance and Twebst Library has support for that. You just have to call Close method against the Browser web automation object you want to close.

Let's see a short JScript web automation macro that closes the first IE8 tab loaded from google.com domain. If the closing tab is the last tab inside the IE frame then the whole browser will be closed.
// Create core object.
var core = new ActiveXObject("Twebst.Core");

// Find a browser for which the displayed URL contains "google.com".
core.useRegExp = true;
var b = core.FindBrowser("url=.*google.com");
b.Close();
There are more Twebst methods for automating IE7 and IE8 tabs that I'll talk about in future articles: OpenNewTab, activeTab, isTabActive, tabList

No comments: