【问题标题】:Open link in new tab?在新的标签页打开链接?
【发布时间】:2011-09-29 19:52:03
【问题描述】:

这是我的尝试。我能想到的最好的办法是让链接在 chrome 扩展中打开。我希望它在新标签页中打开。

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link href="css/style.css" rel="stylesheet"/>
        <script type="text/javascript">
            var items = [];
            var background;

            function init() {
                background = chrome.extension.getBackgroundPage();
                items = background.items;

                createItemTable();
            }

            function createItemTable() {
                var content = document.getElementById("content");
                var list = document.createElement("div");
                list.setAttribute("class", "list");
                content.appendChild(list);

                for (x in items) {
                    var item = items[x];

                    var link = document.createElement("a"); // create the link
                    link.setAttribute('href', "'" + item["link"] + "'"); // set link path
                    link.setAttribute("onclick", "openTab('" + item["link"] + "');");

                    var titleNode = document.createElement("div");
                    titleNode.setAttribute("class", "title");
                    titleNode.appendChild(document.createTextNode(item["title"]));

                    link.appendChild(titleNode);
                    result.appendChild(link);

                    list.appendChild(result);
                }

            }

        </script>
    </head> 
    <body onload="init();" onunload="background.updateBadge();"> 
        <div id="content"></div>
    </body>
</html>

【问题讨论】:

    标签: javascript dom google-chrome-extension


    【解决方案1】:

    试试

    link.setAttribute('target','_blank');
    

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 1970-01-01
      • 1970-01-01
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多