views:

51

answers:

2

Hello,

I'm in a discussion with my co-worker. We have a web application in a tabbed browsing environment, say with 2 tabs open. Tab2 has a link to tab1, when I click the link, it opens tab1 in a new tab. We want to detect if tab 1 is already open, if so then set focus to tab1 (and not open a new window).

He has gotten this working in a broswer window environment, but says it is not possible in a tabbed environment.

Is it possible to for javascript to determine if tab1 is already open and then just set focus to that tab?

Thanks in advance!

A: 

It is only possible if the webbrowser is already preconfigured to open links with a target in a new tab instead of new window and sets focus to it itself when you have given the links the same target name.

E.g.

<a href="http://google.com" target="somename">link1</a>
<a href="http://stackoverflow.com" target="somename">link2</a>
<a href="http://xkcd.com" target="somename">link3</a>

In other words: you're dependent on the client/webbrowser used. You have no control over it from the server side on.


In Firefox for example, the client should have checked both the Open new windows in new tab instead and When I open a link in a new tab, switch to it immediately options to get your requirement to work.

alt text

(as you see, the last one is disabled in mine)

BalusC
So there is no function to check what other tabs are open (provided we know they are using tabbed browsing), and what sites those tabs are pointed to?
jdr120
if your tab is created by using window.open from the tab you want to check, try window.opener. I do not think you can override the user's tab preference using scripts.
Sheng Jiang 蒋晟
A: 

You should instead create a separate document with a DOM-based tab, and iframes pointing to the real pages. Then you could easily set 'focus' to the correct tab when needed.

Sean Kinsey