避免重复的浏览器选项卡或窗口 (window.open()) [英] Avoiding duplicate browser tabs or windows (window.open())

查看:54
本文介绍了避免重复的浏览器选项卡或窗口 (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆