开发者

Open link in new tab?

This was my attempt. The best that I can come up with is getting the link to open up inside the chrome extension. I'd like it to open in a new tab.

<!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>


try

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜