3

I'm building something ONLY for Chrome.

I want to open several tabs with window.open (which Chrome blocks but I can live with enabling it). But Chrome opens them as new windows instead of tabs!

And for some unclear reason I found only information regarding the opposite. How can I achive this?

And if at it, how can I invoke programmatic tab openings without Chrome blocking them?

EDIT: I have seen some posts saying it's not possible and that's it's a browser preference. First of all, I have no idea how to set that preference! Secondly, I saw people claiming they did it, so who to believe to?

EDIT 2: I found out that Chrome opens new windows and not open tabs because it's a JavaScript window opening and not user clicks. Anyone knows how I can fake a real click? Because calling the click event still counts as not user clicks

Community
  • 1
  • 1
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
  • How new windows are opened depends on the settings on the client-side. People who say they forced it are lying :) – PeeHaa Mar 25 '12 at 22:51
  • Can you tell me where in chrome i can choose that? – eric.itzhak Mar 25 '12 at 22:53
  • May be it can help you for what you are looking http://www.google.com/chrome/intl/en/webmasters-faq.html – The Alpha Mar 25 '12 at 23:07
  • As DanH suggests, it *will* work. Try providing a code sample so people can get a better idea of where you might be going wrong! – bPratik Mar 26 '12 at 17:20
  • Where i've gone wrong is that it's not user click its automatic window open on load. any way i can bypass it? calling the click event still not counts as user click... – eric.itzhak Mar 26 '12 at 17:23

2 Answers2

6

If your popup is created by a direct user action (not blocked by the popup blocker) and using the default options it will open in a new tab. If you create it programmatically, it will open as a new window. There is no way to change this behavior.

What you can do, although it is a really bad hack, is create the popup on a user action and then set the location to the final destination using a reference to the popup later on, like the following:

<a href="javascript:;" id="testAnchor" />
var popup1 = null;

document.getElementById('testAnchor').onclick = function() {
    popup1 = window.open('about:blank', 'popup1');
}

  setTimeout(function() {
       popup1.location = 'LOCATION_ON_THE_SAME_ORIGIN_AS_THE_OPENER';

  }, 5000);
Dan Herbert
  • 99,428
  • 48
  • 189
  • 219
  • Can someone point out the place in the chrome settings i can choose this otion? – eric.itzhak Mar 26 '12 at 04:27
  • @eric.itzhak I was mistaken about Chrome having a setting for this. Either this setting was removed from Chrome at some point or it was never an option at all. Regardless, Chrome will always open new windows in a new tab unless you specify custom settings for your windows. – Dan Herbert Mar 26 '12 at 16:12
  • But i'm not specifing and it opens as new window – eric.itzhak Mar 26 '12 at 17:08
  • @eric.itzhak My original tests were using popups that weren't blocked by the browser's popup blocker. I've updated my answer to be more specific about how popups need to be opened to get created in a new tab. Unfortunately, there's no way to do exactly what you want. – Dan Herbert Mar 26 '12 at 17:31
  • Ya It is a very bad hack so i'll just change my plan a bit. But thank you very much kind sir! – eric.itzhak Mar 26 '12 at 17:36
  • If you trigger N window.open from an user interaction, Chrome will open 2 tabs and the rest as pop-ups – Andre Pena Oct 22 '12 at 13:09
  • That's not true... in the end i did that and it works perfectly. – eric.itzhak Nov 01 '12 at 06:26
0

Chrome Add on "One Window": https://chrome.google.com/webstore/detail/one-window/papnlnnbddhckngcblfljaelgceffobn

Automatically moves new Windows and Popups as Tab to the Main-Window. So it is never more than a single Window open.

Martin
  • 2,007
  • 6
  • 28
  • 44
  • That extension link didn't work for me. I found another extension that forces windows to open as tabs: https://chrome.google.com/webstore/detail/open-link-in-same-tab-pop/jmphljmgnagblkombahigniilhnbadca/related?hl=en. This should help me with iMacros. – zeta Nov 01 '18 at 23:00