Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 638
Shashwat Avatar asked Jun 13 '26 16:06

Shashwat


2 Answers

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.

like image 86
Candide Avatar answered Jun 17 '26 09:06

Candide


Give the window a target name: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

New urls wil open in it if exist already

like image 45
Tim Avatar answered Jun 17 '26 09:06

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!