admin管理员组文章数量:1417460
This was my attempt. The best that I can e 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>
This was my attempt. The best that I can e 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>
Share
Improve this question
asked Jul 6, 2011 at 17:10
JonathanJonathan
3,0249 gold badges46 silver badges75 bronze badges
1 Answer
Reset to default 8try
link.setAttribute('target','_blank');
本文标签: javascriptOpen link in new tabStack Overflow
版权声明:本文标题:javascript - Open link in new tab? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745266662a2650642.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论