通过使用JavaScript单击一个窗口打开多个选项卡 [英] open multiple tabs on a single window by a single click using JavaScript

查看:94
本文介绍了通过使用JavaScript单击一个窗口打开多个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在单个窗口中打开多个选项卡,单个链接的新窗口实例不会成为问题,但是当涉及到20+(这是我的情况)时,20多个新窗口确实是一个问题,所以我需要找到一个解决方案,代码必须在chrome上运行,只有在我的情况下,我有35个链接存储在一个数组中。我正在使用for循环读取数组,并使用 window.open()

在新选项卡中打开链接。我只能使用JavaScript。我开发了一个自定义的扩展名。

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 like LinkClump
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]
    });
}

chrome.tabs文档

// will open a new window loaded with all your links
chrome.windows.create({
    url: linkArray
});

chrome.windows文档

无论使用哪种方法,您都需要声明 tabs 权限。

Regardless of which approach you use you will need to declare the tabs permission in your extension's manifest.

这篇关于通过使用JavaScript单击一个窗口打开多个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆