How to set focus to already opened tab in firefox?

后端 未结 5 926
不思量自难忘°
不思量自难忘° 2021-02-19 05:59

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


    Go to Portal

Howe

相关标签:
5条回答
  • 2021-02-19 06:20

    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')
    
    0 讨论(0)
  • 2021-02-19 06:22

    At max you can try target="_blank".

    0 讨论(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!

    0 讨论(0)
  • 2021-02-19 06:36

    No.

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

    0 讨论(0)
  • 2021-02-19 06:40

    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.

    0 讨论(0)
提交回复
热议问题