如何同时打开多个javascript弹窗?

How to open multiple javascript pop ups at the same time?

我正在尝试同时打开多个弹出窗口。我尝试使用循环,但没有 work.I 不明白为什么这不起作用。有一个更好的方法吗?我的代码:

js:

function myFunction() {
            for (var i = 0; i < 5; i++) {
                    window.open("", "MsgWindow", "width=400, height=200");

                }
  }

html:

<button onclick="myFunction()">Try</button>

window.open() 的第二个参数必须是唯一的才能打开新的 window 或者必须设置为 "_blank"

来自 MDN page for window.open():

var windowObjectReference = window.open(strUrl, strWindowName, [strWindowFeatures]);

If a window with the name strWindowName already exists, then strUrl is loaded into the existing window. In this case the return value of the method is the existing window and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location. To open a new window on every call of window.open(), use the special value "_blank" for strWindowName.


注意:现在大多数浏览器都内置了弹出窗口拦截器。这些弹出窗口拦截器通常会允许打开一个新的 window 当它是鼠标单击的直接结果时,但它们可能会施加限制,如果该代码试图打开很多 windows。此弹出窗口阻止程序行为不符合某些规范,因此在不同浏览器的具体实现中可能会有所不同。