15

I have a link which opens a page in a new tab in firefox.

<a target="_default" href='/portal.html' >
    Go to Portal
</a>

However when I click this link again ,it refreshes the opened tab and doesn't set focus to it , so users have no way to know that tab is opened .

Is there any way by which I can grab the opened tab and set focus on subsequent clicks after opening it once Or any other workaround .

Thanks.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sandeep Pathak
  • 10,567
  • 8
  • 45
  • 57
  • Please refer this [link](http://stackoverflow.com/questions/8675320/how-to-focus-on-a-previously-opened-window-using-window-open) It's work for me like a charm. – Milan Sheth Sep 28 '16 at 13:15

5 Answers5

7

For getting the focus using a tabhandler name may help.. suppose we have

win = window.open("https://www.google.com", "test");

win.focus();

now every time the first line of above code runs the browser will first find the tab with the name test and reload it with the url https://www.google.com and in case it does not find a tab with the name test it will open a new one. On the run of the second line it will set the focus to the same tab loaded from the first line.

andrewsi
  • 10,807
  • 132
  • 35
  • 51
dopeddude
  • 4,943
  • 3
  • 33
  • 41
6

I had a similar problem in my project. Luckily, whenever I needed to set focus on already opened tab, it also needed to be refreshed. So I did it with the following trick, which first opened again tab with same href and target, got reference of that window back, closed it, and opened again with same parameters.

popup = window.open('/popup.html', '_popup')
popup.close()
popup = window.open('/popup.html', '_popup')
tzador
  • 2,535
  • 4
  • 31
  • 37
4

No.

Each tab normally runs in a separate process sandbox. It's just not possible.

Strelok
  • 50,229
  • 9
  • 102
  • 115
  • The only work around would be not to open the link in another tab. Either open it replacing the current page or use an iframe to embed the content of the other link in your current page. – Strelok Nov 21 '11 at 06:50
  • I am redirecting to a different webapp , so I would not be able to embed it into the iframe /replace the current page . – Sandeep Pathak Nov 21 '11 at 06:52
  • Yeah I already tried it , each time it opens a new tab . Thanks – Sandeep Pathak Nov 21 '11 at 07:07
  • I think this might be the best option in terms of "attracting attention" of the user. – Strelok Nov 21 '11 at 07:13
1

At max you can try target="_blank".

stema
  • 90,351
  • 20
  • 107
  • 135
upendra
  • 49
  • 6
0

You can probably use _blank and some JS code that closes a previously opened tab for the same URL using cookie tracking.

The page (that you are opening in the new tab) should be built in such a way that it writes out a cookie with some value (say current time in millis). It should also have some kind of a periodic poller that checks the value of this cookie and closes itself when the value is seen to be changed. the only way this value can change is when the same url is opened in another tab/popup.

Disclaimer: Not sure if browsers will allow window.close without it being user triggered though!

techfoobar
  • 65,616
  • 14
  • 114
  • 135