-2

I need to open a URL in a new window the first time it is opened. The second time, the URL should open as a tab in that newly-created window. I tried with window.open(url, "", "width=900, height=900");, but it is opening in a new window each time.

Is it possible to force the URL to open in a tab after it the new window is created?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Chethan S
  • 19
  • 2
  • please provide an [mcve] – Sagar V Jul 18 '17 at 13:20
  • 1
    https://stackoverflow.com/a/15551933/4629808 – Thomas Jul 18 '17 at 13:22
  • I don't think that there is any way to have such granular control over how the browser opens webpages. (Of course, the user can always override what you request the browser to do. For example, I only use tabs and never allow new windows to be opened.) – Sumner Evans Jul 18 '17 at 16:18
  • Possible duplicate of [Open a URL in a new tab (and not a new window) using JavaScript](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript) – Deeptechtons Jul 18 '17 at 19:15

1 Answers1

3

This is impossible.

  • You can trigger a new viewport in a new window (as you have discovered) by giving dimensions to it.
  • You can trigger a new viewport in a new window/tab (user preference) by not giving dimensions and giving the viewport no name or a new name
  • You can reuse an existing viewport by using its name

You can never choose to open in a new tab at all. When a new tab is triggered, you cannot control which window it appears in.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335