避免重复的浏览器选项卡或窗口 (window.open()) [英] Avoiding duplicate browser tabs or windows (window.open())
问题描述
在 Javascript 中,我们可以使用 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?
推荐答案
第二个参数 of window.open(strUrl, strWindowName[, strWindowFeatures]);
是窗口名称.如果您指定该参数,对于_blank"以外的任何内容,它将引用已打开的选项卡/窗口.
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.
例如:
window.open('/about', 'newwindow');
和
window.open('/contact', 'newwindow');
将在已经打开的窗口/标签中打开页面.
will open the page in an already opened window/tab.
这篇关于避免重复的浏览器选项卡或窗口 (window.open())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!