Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - Open multiple links in Chrome at once as new tabs

I'm trying to open multiple links at once in Google Chrome in new tabs but it fails.

Problems:

  1. Blocked by popup
  2. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...