Tim S.
Tim S.

Reputation: 385

Is it possible to use a link on a website to change browser tabs?

Basically I want to have a button/link that opens google in a new tab, but if that tab is already open then just focus that tab. Is this possible?

Upvotes: 0

Views: 69

Answers (3)

icktoofay
icktoofay

Reputation: 129069

Kind of. The closest thing I can think of would be something like this:

<a href="http://www.example.com/" target="example">Link</a>

When you click it the first time, it will open the link in a new tab. Subsequent clicks of the link will navigate the tab it opened the first time (even if that tab has since navigated to a different page). It will not change the page of a tab that was opened without using the link.

Upvotes: 3

konieckropka
konieckropka

Reputation: 499

Yes, you can and it is quite simple task - but remember that nowadays some browsers (With addons) will either block a new window you create or will not recognize it as "pop-up" that can be controled in some internal JavaScript.

Proper method is:

<script>
var myTab;

function openIt()
{
myTab=window.open('','','width=200,height=100');
myTab.document.write("<p>Some kind of inner text</p>");
myTab.blur(); // this will un-activate opened window/tab
}

function activateIt()
{
myTab.focus();
}
</script>


<input type="button" value="Open" onclick="openIt()">
<input type="button" value="Activate" onclick="activateIt()" />

To controll it see documentation for window.open() method.

Upvotes: 1

Andy Ray
Andy Ray

Reputation: 32076

Nope.

you can focus a window that you've opened with window.open and have a reference to with window.focus ( MDN ), sometimes.

You might be able to do this with a browser plugin, depending on the browser.

Upvotes: 2

Related Questions