1

I call two window.open, but only the first one seems to be working. What is going on there?

<button id="open-two">Open two windows</button>

var openTwo = document.getElementById("open-two");
openTwo.addEventListener("click", function() {
    window.open("http://bing.com");
    window.open("http://google.com");
});

A fiddle here

I am using Chrome when testing this.

Leo
  • 4,136
  • 6
  • 48
  • 72

1 Answers1

3

It's the built-in popup blocker. Chrome (correctly) thinks you're opening a lot of windows, so it tries to stop you. You can confirm this by looking for a little icon with a red X on the right side of the address bar in the original window.

You will either need users to disable the popup blocker or find a different way to do this.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • Thanks Ed, yes that seems to be the problem. ;-) -- Testing using setTimeout. – Leo Apr 02 '14 at 01:36
  • My understanding is that Chrome keeps track of the total number of windows you have attempted to open, so setTimeout won't help. The only sure-fire way around this is to make each new window open in response to a distinct user action (i.e., one action per window that you want to open). You might find [this question and its answers](http://stackoverflow.com/questions/4602964/how-do-i-prevent-google-chrome-from-blocking-my-popup) helpful. – elixenide Apr 02 '14 at 12:09
  • Yes, it is my understanding to. That page is helpful, thanks. The suggestions in the accepted answer are very good. – Leo Apr 02 '14 at 15:50