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

后端 未结 3 1994
名媛妹妹
名媛妹妹 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:07

    Solotion: Use setTimeout! With more and more time values

    javascript:
    var a=document.location.href;
    for (var i=0;i<50;i++){
        setTimeout('window.open(a)',i*200);
    }
    void(0);
    

    This will clone the current tabs 50 times, even in Chrome! Unfortunately, in new Windows instead of new tabs. Silly Chrome :-)

    0 讨论(0)
  • 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.

    0 讨论(0)
  • You can use target="_blank" attribute of a link for opening the corresponding page in new tab.

    0 讨论(0)
提交回复
热议问题