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?
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.
(as you see, the last one is disabled in mine)
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.
精彩评论