open multiple tabs on a single window by a single click using JavaScript

后端 未结 3 2065
名媛妹妹
名媛妹妹 2020-12-18 12:46

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

3条回答
  •  醉酒成梦
    2020-12-18 13:15

    I wasn't sure if you wanted the links to be open in a new window or not so I've included both possibilities;

    Same Window

    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 documentation

    New Window

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

    chrome.windows documentation

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

提交回复
热议问题