Search code examples
javascriptfirefoxwindow.open

window.open(url, target) doesn't activate a tab in Firefox


This simple code:

<button onclick="window.open('https://google.com', 'my-tab')">open google</button>

Works fine in Chrome, but in Firefox (latest v75) it opens always, but activates a new tab only the first time.

Live demo: https://jsfiddle.net/nmp049Lu/1/

Steps to reproduce

  1. click the button, a new tab with google in it should be opened and active
  2. do not close the newly opened tab, but go back to the live demo tab
  3. click the button again

Expected behavior

The same tab as in step 2 gets opened and activated (gets visible)

Actual behavior

The same tab as in step 2 gets opened but not activated (doesn't get visible)

Is this a bug in Firefox or I'm missing something?


Solution

  • Here try this:

    <button onclick="window.open('https://google.com', 'my-tab').focus()">open google</button>