简体   繁体   中英

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM