Java多人父母的一个孩子窗口

时间:2018-08-09 03:16:20

标签: javascript

假设我在浏览器选项卡中有domain.com/a.html,并在单击该页面上的按钮后打开了一个弹出窗口(domain.com/b.html)。现在,如果我在另一个选项卡中打开了domain.com/a.html,并且在第二个选项卡上单击了相同的按钮,则需要将第一个弹出窗口置于前台,而不要在其中打开同一页面(/b.html)。第二个弹出窗口。这有可能吗?

1 个答案:

答案 0 :(得分:0)

我假设您使用window.open并且未指定第二个参数,即窗口名称?

如果定义唯一的窗口名称,则将为每个链接打开新的浏览器窗口。

示例:

<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>

为使同一按钮每次单击都可以打开新窗口,只需在窗口名称中添加随机因素,例如:

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

window.open docs here

相关问题