2

I would like to know if it's possible to activate an opened window tab when I click on a link from a different window.

e.g. I click on a _blank link from website A, which opens a new window for website B. Now, usually if I want to go back to website A from website B, I have to close website B or look for website A manually.

Is it possible to create a link in website B which will activate the already opened website A?

Wasif Ali
  • 886
  • 1
  • 13
  • 29
Jay Smoke
  • 573
  • 3
  • 13
  • 35
  • You mean u have opened Website A in one tab and B in another. When your link on Website B is clicked browser should switch to website A tab? – Nameless Aug 22 '17 at 11:29
  • If this is what u want, i'm afraid you can't do it. Refer to this - https://stackoverflow.com/questions/15601190/is-it-possible-to-switch-browser-tab as it is actively blocked in most of the browsers. – Nameless Aug 22 '17 at 11:32
  • yup exactly that – Jay Smoke Aug 22 '17 at 11:32
  • 2
    2 different website? Nope. It would be possible using an userscript tho with maybe an interval and localstorage. But for normal javascript and two different website that's totally impossible. – user5014677 Aug 22 '17 at 11:33
  • @user5014677 sorry I didn't state...the two sites are yours not external sites. In other words, you developed them both so you can manipulate them anyhow you want. – Jay Smoke Aug 22 '17 at 11:35
  • Can u state the purpose for which you are trying to implement this? Somebody could suggest an alternative. – Nameless Aug 22 '17 at 11:38
  • It's to move from CMS to website and vice versa! So that when you are working in the CMS, you don't have to fish for your website or always have to open a new tab when you want to see the changes on the website. If you can create a link in the CMS that will activate the website which is already opened, that would be great. – Jay Smoke Aug 22 '17 at 11:40
  • I'm not sure if script can have access to browser's tabs. If it was, it would be a huge securty flaw. You can launch the website's URL everytime you click the link, which opens website in new tab. But opening the current tab, i'm not sure. – Nameless Aug 22 '17 at 11:47

2 Answers2

0

It is not possible due to obvious security reasons :D

If you have refered tabs as window in this context, you can try popping up your website as a new window and calling focus() on it

yourPopupName.focus();

can focus on the popped up window.

Reference: How to change browser focus from one tab to another

Nameless
  • 1,026
  • 15
  • 28
0

Theoretically it's not possible but maybe this could work:

Basicly since it's the same website you can store a variable somewhere like in local storage in the tabB like this when ever you need to go back to tabA:

localStorage['update'] = true

Then on tabA where you opened the tabB following your example you can make an interval to check if it has to be updated or what ever with a setInterval function.

setInterval(function(){
     if (localStorage['update'] == true){
       localStorage['update'] = false;
       $.get(location.href, function(){window.open(location.href)}, 'html');

       window.opener = window;
       window.close(); 
     }
}, 5000);

So this will basicly check every 5seconds if it has to be updated, if yes then it sets the update back to false or it will keep refreshing the page, then it opens a new and close itself that will force the browser to focus on the new tab.

It's not exactly what you want to achieve but it's as close as you can get with js.

If you don't want to refresh instead of $.get(... you can just make an alert so the title of the tab will be bold so the user will know that something happens there.

I haven't tested this but you got the idea.

user5014677
  • 694
  • 6
  • 22