Avoiding duplicate browser tabs or windows (window.open())

Shashwat picture Shashwat · Feb 29, 2012 · Viewed 9.6k times · Source

In Javascript, we can use window.open() to open a new browser window or tab. But if a tab is already open, it should highlight that only. It should not open duplicate tabs. How to do that?

Answer

Candide picture Candide · Feb 29, 2012

The second argument of window.open(strUrl, strWindowName[, strWindowFeatures]); is the window name. if you specify that parameter, to anything other than "_blank" it will refer to the already opened tab/window.

For instance:

window.open('/about', 'newwindow');

and

window.open('/contact', 'newwindow');

will open the page in an already opened window/tab.