Open multiple links in Chrome at once as new tabs
Solution 1
You can do this in vanilla JavaScript:
<html>
<head>
<script type="text/javascript">
function open_win() {
window.open("http://www.java2s.com/")
window.open("http://www.java2s.com/")
}
</script>
</head>
<body>
<form>
<input type=button value="Open Windows" onclick="open_win()">
</form>
</body>
</html>
Here is a more Chrome-specific implementation (if popup blockers are giving you difficulty):
var linkArray = []; // your links
for (var i = 0; i < linkArray.length; i++) {
// will open each link in the current window
chrome.tabs.create({
url: linkArray[i]
});
}
Here is some documentation: https://developer.chrome.com/extensions/tabs
Solution 2
The reason that the browser extension can do it is because Chrome extensions have access to a special Chrome API, which lets you use:
chrome.windows.create({tabid: n})
where createData
has a tabid
value greater than any current tab (and you can find the greatest current tabid
using chrome.windows.getAll()
).
However, in terms of doing it on your page (or anywhere that's not a Chrome extension), that's not possible, since whether or not a new window opens in a new tab is determined entirely by the user's settings.
Solution 3
User will have to allow popups but I ended up doing this:
function openMultipleTabs(urlsArray){
urlsArray.forEach(function(url){
let link = document.createElement('a');
link.href = url;
link.target = '_blank';
link.click();
});
}
Solution 4
The best way to open multiple tabs or windows is by using setTimeout()
of 500ms.
window.open("https://facebook.com", "one", windowFeatures);
setTimeout(function(){
window.open("https://facebook.com", "two", windowFeatures);
}, 500);
Related videos on Youtube
user3522725
Updated on August 19, 2022Comments
-
user3522725 over 1 year
I'm trying to open multiple links at once in Google Chrome in new tabs but it fails.
Problems:
- Blocked by popup
- Open in new windows instead of tab after the user allowed the popup
With this, I can open multiple links at once in Firefox:
<!DOCTYPE html> <html ng-app="plunker"> <head> <meta charset="utf-8"> <title>AngularJS Plunker</title> <script>document.write('<base href="' + document.location + '" >');</script> <link rel="stylesheet" href="style.css"> <script data-require="[email protected]" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js" data-semver="1.2.17"></script> <script src="app.js"></script> </head> <body ng-controller="MainCtrl"> <button ng-click="openLinks()">Open</button> </body> </html>
Also, I came across someone who found a workaround.
I tried using
setInterval
to try to open the links individually but it didn't work.-
Admin almost 10 yearsThis seems a little iffy, you're trying to bypass popup blocks even though they were made for this specific reason, to block popups... :L
-
user3522457 almost 10 yearsI'm not doing some fishy stuff.. look at the extension, how the developer bypassed it? hmm
-
Patrick Collins almost 10 yearsDo you want to do that independently of browser settings? I don't think that that's possible.
-
Maverick almost 10 yearsWhile it may be interesting to look at the code of a browser extension, this code WILL NOT WORK on a website.
-
Maverick almost 10 yearsThis is correct. Browser extensions can do a lot more than a webpage can. Despite both using javascript, they are very, very different things.
-
Patrick Collins almost 10 years
chrome.tabs.create
is part of the Chrome API that I discussed in my answer -- it's not going to work on a webpage. -
nyzm almost 10 yearsI know it won't work in a webpage since it uses chrome api. That was for answering his question about how extension developer achieved it.
-
Arthur over 8 years"vanilla JavaScript" works nicely in your example. but a page with multiple open_win functions (and corresponding buttons) does not open multiple tabs for each button:
-
Kaddath over 6 yearsthe "vanilla JavaScript" is no longer working in chrome (January 2018), it's opening a single tab, not two..
-
tfantina almost 6 yearsAs of July 2018 I believe the best solution is something like this:
window.open("https://www.ecosia.org", "_new"); window.open("https://www.duckduckgo.com", "secondWindow");
The trick is to make sure that the second window has a name other than_new
otherwise the browser will try to stick the link into the same window overriding the firstwindow.open
. I have tried this in Chrome and IE and it works for me. -
Ethan Allen over 4 yearsAs of Nov 2019, tfantina's code only opens one tab on mobile Safari (iOS 13.2). Works fine on Mac Safari (13.0.3) though.
-
Flimm over 4 yearsThis only opens it in one tab for me.
-
Serge about 3 yearsCould you give a test reference where such a solution works ? Tnx in advance
-
Don Kartacs about 3 years
-
Revisto almost 3 yearsdude, your second solution was awesome.