我正在创建Trello卡中的链接到外部链接。我想要实现的是,此链接在同一浏览器选项卡(_self)中打开,或在新的浏览器选项卡中打开,如果再次激活链接,则返回此选项卡。现在它每次点击链接时都会生成一个新的浏览器选项卡。有什么建议可以实现这个目标吗?
答案 0 :(得分:0)
您可以设置特定窗口的名称,以便打开重复使用选项卡。您可以通过以下方式进行操作。
<a href="foo" onclick="window.open(this.href, this.href); return false">Foo</a>
<a href="bar" onclick="window.open(this.href, this.href); return false">Bar</a>
或者这样也.. ..
<div id="tabopen">
<a href="bar">link</a>
</div>
<script>
document.getElementById("tabopen").onclick = function(evt){
if (evt.target.tagName === "A")
window.open(evt.target.href, evt.target.href);
return false;
}
</script>