简体   繁体   中英

new window doesn't open as tab in Chrome

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

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM