1

Suppose I have domain.com/a.html in a browser tab, and a popup (domain.com/b.html) opened upon a button click on that page. Now, if I have domain.com/a.html open in another tab and the same button is clicked on the second one, I need to bring the first popup to the foreground and not open the same page (/b.html) in a second popup. Is this possible at all?

FreeBird
  • 691
  • 1
  • 8
  • 18
  • Probably some [relevant information here](https://stackoverflow.com/questions/3311293/javascript-bring-window-to-front-if-already-open-in-window-open), but as far as I'm aware you'd have to close and re-open it. Perhaps I'm wrong on that though. – Tyler Roper Aug 09 '18 at 03:19
  • Possible duplicate of [Open link in new window or focus to it if already open](https://stackoverflow.com/questions/10982593/open-link-in-new-window-or-focus-to-it-if-already-open) – Ashraf Aug 09 '18 at 03:38

1 Answers1

1

I assume you use window.open and don't specify second parameter, which is window name?

If you define unique window names you will see new browser windows open for each link.

Example:

<a href="javascript:window.open('http://example.com/a.html', 'window1')">
    link 1
</a>
<a href="javascript:window.open('http://example.com/b.html', 'window2')">
    link 2
</a>

In order for the same button to open new windows each time it clicked just add random factor to window name like:

<a href="javascript: window.open('http://example.com/a.html', 'window' + Math.floor((Math.random()*100)+1))">
    link
</a>

window.open docs here

Seva Kalashnikov
  • 4,262
  • 2
  • 21
  • 36