问题描述
我需要在单个窗口上打开多个选项卡,单个链接的新窗口实例不会有问题,但是当涉及 20+(这是我的情况)时,20+ 新窗口确实是个问题,所以我需要找到一个解决方案,仅在我的情况下,代码必须在 chrome 上运行,我有 35 个链接存储在一个数组中.我正在使用 for 循环读取数组并使用 window.open()
在新选项卡中打开链接我只能为此使用 JavaScript.我正在开发一个定制的 chrome 扩展.
I need to open multiple tabs on a single window, new window instance for a single link will not be a problem but when it comes to 20+ (which is my case) then 20+ new windows are really a problem, so I need to find a solution, the code has to run on chrome only in my case I have 35 links stored in an array. I am reading array using a for loop and opening links in new tabs using window.open()
I can use only JavaScript for this. I am developing a customized chrome extension.
我发现,当使用 window.open()
在 Google Chrome 中打开同一窗口的不同选项卡中的多个链接时,它只成功打开了前 24 个窗口而忽略了其余窗口.
我需要找到一种方法来一次单击打开所有链接.
I found out that while using window.open()
to open multiple links in different tabs of a same window in Google Chrome, it succeeds in opening only first 24 windows and left out the rest.
I need to find out a way to open all the links at once with a single click.
有一些可用的 Google Chrome 扩展程序可以像这样工作LinkClump
此扩展程序成功打开同一窗口的不同选项卡中的所有选定链接.我正在尝试修改其工作以适合我的情况.
There are some Google Chrome Extensions available which work like this likeLinkClump
This Extension successfully open all selected links in different tabs of a same window. I am trying to modify its working to suit mine.
同时,如果有人能得到任何解决方案,他/她是最受欢迎的.
Meanwhile, if anyone can get any solution, he/she is most welcome.
推荐答案
我不确定你是否希望在新窗口中打开链接,所以我已经包含了两种可能性;
I wasn't sure if you wanted the links to be open in a new window or not so I've included both possibilities;
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]
});
}
// will open a new window loaded with all your links
chrome.windows.create({
url: linkArray
});
无论您使用哪种方法,您都需要在您的扩展的清单.
Regardless of which approach you use you will need to declare the tabs permission in your extension's manifest.
这篇关于使用 JavaScript 通过单击在单个窗口上打开多个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!