1

My browser allows any website to show pop-ups (made using window.open).

window.open("http://www.google.com/","_blank");

The above code opens google.com on a new tab.


However, when I use window.open repeatedly like this:

window.open("http://www.google.com/","_blank");
window.open("http://www.facebook.com/","_blank");
window.open("http://www.example.com/","_blank");

Now, google.com is opened on a new tab, while facebook.com and example.com are opened as pop-up windows. I actually want to have the 3 links to open in new tabs but I can't achieve that.

How can I fix this?

1 Answers1

1

I'm surprised the second and third get opened at all. (They don't on Chrome, it blocks them; but I do see the behavior you describe if I disable the blocker.)

You'll need to provide separate UI elements (buttons, whatever) to open each window individually, so that each window.open call is triggered by a separate end-user action, rather than opening several windows in response to a single user action. Hopefully that will give you the behavior you desire for each individual window. Although you don't have control over whether something opens in a new window or a tab, most browsers default to new tabs these days (and most have an option for users to change it) unless you supply the third argument to window.open, in which case they may open a new window instead using the settings you pass in that argument.

Since Chrome does this unusual thing with the second and third calls, limiting yourself to a single open per user action should work in most cases, as in most cases the default is a new tab, not a new window.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I'm using Chrome and they *do* open –  May 30 '14 at 07:40
  • That's because the other pop-ups were blocked by your browser, I think –  May 30 '14 at 07:42
  • What do you mean by `suggest to the browser that it use a new window by supplying the third parameter to window.open`? –  May 30 '14 at 07:47
  • @user3553493: I mean if you give the third argument to `window.open` (the one where you specify what window controls there should be, the size of the window, etc.), the browser will usually (not always) open a new window rather than a new tab. That won't help you if your goal is to open new tabs. – T.J. Crowder May 30 '14 at 07:48
  • If my goal is to open new tabs, what should I put in the third parameter then? I tried `fullscreen=yes` but in the end, none of the links were opened in new tabs. –  May 30 '14 at 07:52
  • Please elaborate more –  May 30 '14 at 07:58
  • @user3553493: As far as I know, there's nothing you can put in the third argument that will tell the browser to use a new tab; putting things there usually makes the browser use a new window instead. As I said in the answer, since using a new tab is the default in most cases, you'll have to open these windows individually, each in response to its own user event. – T.J. Crowder May 30 '14 at 08:04