Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set focus to already opened tab in firefox?

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.

like image 208
Sandeep Pathak Avatar asked Nov 21 '11 06:11

Sandeep Pathak


2 Answers

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.

like image 139
dopeddude Avatar answered Oct 07 '22 20:10

dopeddude


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')
like image 27
tzador Avatar answered Oct 07 '22 20:10

tzador