最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

for loop - How to open multiple javascript pop ups at the same time? - Stack Overflow

programmeradmin0浏览0评论

Im trying to open multiple pop ups at the same time. I tried using loops, but it didnt work.I don't understand why this doesn't work. Is there a better way to do this? My code:

js:

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

                }
  }

html:

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

Im trying to open multiple pop ups at the same time. I tried using loops, but it didnt work.I don't understand why this doesn't work. Is there a better way to do this? My code:

js:

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

                }
  }

html:

<button onclick="myFunction()">Try</button>
Share Improve this question asked Mar 6, 2015 at 4:21 user1930115user1930115 1,0532 gold badges12 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The second argument to window.open() must be unique for it to open a new window or must be set to "_blank".

From the 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.


Note: most browsers these days have popup blockers built in. Those popup blockers will generally allow one new window to be opened when it is the direct result of a mouse click, but they may impose limits if the code is trying to open lots of windows. This popup blocker behavior is not per some specification so it likely varies in detailed implementation from browser to browser.

发布评论

评论列表(0)

  1. 暂无评论