Chrome扩展程序:链接收藏家

时间:2013-12-12 23:51:28

标签: javascript html google-chrome

popup.js:

function GetUrls()
    {
    var fourmTabs = new Array();
    chrome.tabs.query({}, function (tabs) {
        for (var i = 0; i < tabs.length; i++) {
            fourmTabs[i] = tabs[i];
        }
        for (var i = 0; i < fourmTabs.length; i++) {
            if (fourmTabs[i] != null)
            {
            document.write("<b>" + fourmTabs[i].title + "</b>" + "<br/><a href='" + fourmTabs[i].url + "'>" + fourmTabs[i].url + "</a><br/><br/>");
             }  
            else {
                document.write("??" + i);
            }
        }
    });
    }
    window.addEventListener("DOMContentLoaded", GetUrls());

    function OpenInNewTab(url )
    {
     var win=window.open(url, '_blank');
      win.focus();
    }
     //document.addEventListener('??', OpenInNewTab(??));

现在新的选项卡步骤..如何使用GetUrls函数中的局部变量的url调用OpenNewTab函数?还是有更好的主意??

1 个答案:

答案 0 :(得分:0)

我不确定你想要什么。在任何情况下,getSelected都不推荐使用query,因此您应该使用它:

window.addEventListener("DOMContentLoaded", function() {
    chrome.tabs.query({
        // All tabs in current window
        currentWindow: true
    },
    function(tabs) {
        var olTag = document.createElement("ol");
        for (var i = 0, len = tabs.length; i < len; i++) {
            // Create a list-item for each tab
            var liTag = document.createElement("li");
            liTag.appendChild(document.createTextNode(tabs[i].url));
            olTag.appendChild(liTag);
        }
        document.body.appendChild(olTag);
    });
});

此代码列出了您打开的所有标签的网址,如下所示:

These are links you open:

    1. http://stackoverflow.com/posts/20557596/edit
    2. chrome://extensions/