We ran into a usecase where a user has to explicitly target a tab in ie. For example users have logged into salesforce.com cloud in one window. These users are then taking calls in that window. However same users are using another internet application to complete their work. It would be messy to open up these multiple windows every time work needs to be done.

It is probably better to target just one window and the user transferred to one window. Better yet to target a specific tab.

So started my search. I thought it ought to be simple. As it turned out there doesnt seem to be a good way to do this through regular unsigned javascript in ie7. I did find a way to do this in firefox.

ie seem to control tab vs new window purely through user configuration. Users can choose to set a global ie option to open new windows targeted by "_blank" to either an actual new window or a tab. Once they set this option as tab then the simple window.open(url) will open that url in a new tab.

I still want to force to open in a new tab. Perhas I will find a way through signed javascript. that is for another day or week.

If you are further curious what follows is my research and notes on how I came to this conclusion.

satya - Thursday, May 13, 2010 10:35:38 AM

How to target an ie tab from javascript

How to target an ie tab from javascript

Search for: How to target an ie tab from javascript

satya - Thursday, May 13, 2010 10:38:58 AM

May be there is something here. not sure. read later

May be there is something here. not sure. read later

satya - Thursday, May 13, 2010 10:42:12 AM

is there a way to configure or precreate tabs in ie

is there a way to configure or precreate tabs in ie

Search for: is there a way to configure or precreate tabs in ie

satya - Thursday, May 13, 2010 10:46:36 AM

open a link in a new tab larry williams

open a link in a new tab larry williams

Search for: open a link in a new tab larry williams

satya - Thursday, May 13, 2010 10:47:48 AM

perhaps here

perhaps here

satya - Thursday, May 13, 2010 11:35:57 AM

using javascript instead of target to open new windows

An interesting read (no solution yet)

using javascript instead of target to open new windows

satya - Thursday, May 13, 2010 11:43:15 AM

can i get a list of ie tabs through javascript

can i get a list of ie tabs through javascript

Search for: can i get a list of ie tabs through javascript

satya - Thursday, May 13, 2010 11:43:52 AM

tabs parent and child windows in ie

tabs parent and child windows in ie

Search for: tabs parent and child windows in ie

satya - Thursday, May 13, 2010 1:05:53 PM

A general user level introduction to how tabs behave in ie7

A general user level introduction to how tabs behave in ie7

satya - Thursday, May 13, 2010 1:07:25 PM

ie7 behavior from the developers mouth

ie7 behavior from the developers mouth

satya - Thursday, May 13, 2010 1:21:12 PM

Not sure how one might use this but here is a ref to IWebBrowser2 ie interface

Not sure how one might use this but here is a ref to IWebBrowser2 ie interface

satya - Thursday, May 13, 2010 1:26:23 PM

The ie7Blog

The ie7Blog

satya - Thursday, May 13, 2010 1:29:06 PM

Jscript blog

Jscript blog

satya - Thursday, May 13, 2010 1:31:08 PM

jquery targeting tabs

jquery targeting tabs

Search for: jquery targeting tabs

satya - Thursday, May 13, 2010 1:48:12 PM

you may want to read up on ie automation

you may want to read up on ie automation

satya - Thursday, May 13, 2010 1:49:20 PM

ie access to browser object from javascript

ie access to browser object from javascript

Search for: ie access to browser object from javascript

satya - Thursday, May 13, 2010 2:05:36 PM

javascript access to "tab" objects

javascript access to "tab" objects

Search for: javascript access to "tab" objects

satya - Thursday, May 13, 2010 2:08:00 PM

list all windows open in javascript

list all windows open in javascript

Search for: list all windows open in javascript

satya - Thursday, May 13, 2010 2:13:23 PM

A nice summary of windows using javascript

A nice summary of windows using javascript

satya - Thursday, May 13, 2010 3:55:16 PM

Here is an html file to test new window stuff


<html>
<head>
<script>
function say()
{
	alert('hello');
}
var nw = null;
function newwindow()
{
	nw = window.open();
}
function closewindow()
{
	nw.close();
}
function gotowindow()
{
	nw.focus();
}
</script>
</head>
<body onload="javscript:say()">
<p>hello</p>
<form>
<input value="OpenWindow" type="button" onClick="javascript:newwindow()"/>
<input value="CloseWindow" type="button" onClick="javascript:closewindow()"/>
<input value="focus" type="button" onClick="javascript:gotowindow()"/>
</form>
</body>
</html>

satya - Thursday, May 13, 2010 10:27:49 PM

In the receiving window the other window is known as


opener
or
window.opener

satya - Friday, May 14, 2010 4:18:56 PM

Documentation on open method

Documentation on open method

satya - Friday, May 14, 2010 4:20:44 PM

Example of open methods


var nw = null;
function newwindow()
{
	//this works
	//load into a new unnamed window
	nw = window.open("http://www.google.com","_blank");

	//this works
	//load into a new named window
	//allows for "target" spec
	//nw = window.open("http://www.google.com", "mywindow");
	
	//but this does not work
	//not sure what the space is doing
	//nw = window.open("http://www.google.com", "my window");

	//this works
	//creates a window that doesnt go anywhere	
	//nw = window.open("about:blank");
	
	//this works
	//creates an "about:blank"
	//nw = window.open();
}

satya - Friday, May 14, 2010 4:39:22 PM

A better example putting all together


<html>
<head>
<script>
function say()
{
	//alert('hello');
}

var nw = null;
function newwindow()
{
	//this works
	//load into a new unnamed window
	nw = window.open("http://www.google.com","_blank");

	//this works
	//load into a new named window
	//allows for "target" spec
	//nw = window.open("http://www.google.com", "mywindow");
	
	//but this does not work
	//not sure what the space is doing
	//nw = window.open("http://www.google.com", "my window");

	//this works
	//creates a window that doesnt go anywhere	
	//nw = window.open("about:blank");
	
	//this works
	//creates an "about:blank"
	//nw = window.open();
}

function createwindow()
{
	if (isValidWindow() == false)
	{
		newwindow();
		return;
	}
	alert("A window is already created. use focus button to go there.");
}

function closewindow()
{
	if (nw == null)
	{
		alert ("Thsi window is not created. Click on open window to create one.");
		return;
	}
	if (nw.closed == true)
	{
		alert("window is already closed");
		return;
	}
	nw.close();
}

function isValidWindow()
{
	if (nw == null)
	{
		return false;
	}
	if (nw.closed == true)
	{
		return false;
	}
	return true;
}

function gotowindow()
{
	if (isValidWindow() == true)
	{
		nw.focus();
		return;
	}
	alert("sorry no window was created prior or closed");
}
function gotoMS()
{
	if (isValidWindow())
	{
		//this seem to have a security restriction
		//nw.document.location="http://www.microsoft.com";
		
		//but this will work
		nw.navigate("http://www.microsoft.com");
		nw.focus();
	}
	alert("Invalid window. Create one by using Open to test it");
}
function gotoGoogle()
{
	if (isValidWindow())
	{
		//nw.document.location="http://www.google.com";
		nw.navigate("http://www.google.com");
		nw.focus();
		return true;
	}
	alert("Invalid window. Create one by using Open to test it");
}
</script>
</head>
<body onload="javscript:say()">
<h2>Welcome to new window tester</h2>
<form>
<p>This will open a new window and remembers its handle. 
If ie is set to open in tabs then it will result in a tab.
<p>
<input value="OpenWindow" type="button" onClick="javascript:createwindow()"/>
</p>

<p>
<p>This will close the opened window or tab as a result
<p>
<input value="CloseWindow" type="button" onClick="javascript:closewindow()"/>
</p>


<p>
<p>This will shift the focus to the window that was created.
<p>
<input value="focus" type="button" onClick="javascript:gotowindow()"/>
</p>

<input value="Go to Google" type="button" onClick="javascript:gotoGoogle()"/>
<input value="Go to Microsoft" type="button" onClick="javascript:gotoMS()"/>
</form>
</body>
</html>

satya - Saturday, May 15, 2010 9:59:12 AM

You can test this by clicking on the link below

You can test this by clicking on the link below

Or you can do a save as on that link to download that file to your local hard disk and try it from there.

satya - Thursday, January 20, 2011 1:48:04 PM

A few glitches with the idea

This code works if the open window targets a new window and not a tab. Especially focus. The focus works like a charm for new windows. However it doesn't work for tabs.

The very first time a URL is open in a new tab, the focus shifts to that new tab. However any subsequent opens or navigations or focus changes are not honored for that tab.

The work around seem to be first you obtain a javascript window pointer by opening tab with the same name as before. This gives us a window pointer. use that window pointer to close the named tab. Then reopen the tab with the same name. This time being a new tab it will shift the focus.

Howver this seems to be slightly erratic in field tests. It works 99% of the time. It is not clear what the hiccup is.

satya - Thursday, January 20, 2011 1:49:19 PM

Another thread I have started to see how to create ie plugins

Another thread I have started to see how to create ie plugins

To see if a plugin can address the problem more consistently.