简体   繁体   English

Window.open 无缘无故地打开一个空白的新标签

[英]Window.open opens a blank empty new tab for no reasons

So I have a very simple link that tries to open 2 new tabs:所以我有一个非常简单的链接,试图打开 2 个新标签:

 function multipleTabs() { window.open("http://firstlink/","_blank"); window.open("http://secondlink/","_blank"); return false; }
 <a href="javascript:void(0);" onclick="multipleTabs();">Open 2 tabs</a>

The issue is that when I click the link, the 2 tabs are opened fine but it appears another blank new tab, for a total of 3 new tabs.问题是,当我单击链接时,2 个选项卡可以正常打开,但出现另一个空白的新选项卡,总共有 3 个新选项卡。

How can I prevent the third blank tab to be opened?如何防止打开第三个空白选项卡?
Note: you have to allow the pop up in your chrome page to make this working注意:您必须允许 chrome 页面中的弹出窗口才能使其正常工作

PS.附注。 the solution can be also just chrome specific as I don't use other browser for this page.该解决方案也可以是特定于 chrome 的,因为我没有为此页面使用其他浏览器。

Try:尝试:

<a href="javascript:multipleTabs()">Open 2 tabs</a>

I usually avoid using javascript:void(0) as long as I can for avoiding this type of issues, however for some reason both works-for-me.我通常会尽量避免使用 javascript:void(0) 来避免此类问题,但是出于某种原因,两者都对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM