我有来自第三方开发人员的JavaScript文件。 它具有一个具有链接的链接,该链接将当前页面替换为目标页面。 我想在新标签页中打开此页面。
这是我到目前为止的内容:
if (command == 'lightbox') {
location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual";
}
谁能帮我吗?
#1楼
如果要使用location.href以避免弹出问题,可以使用空的<a>引用,然后使用javascript单击它。
类似HTML
<a id="anchorID" href="mynewurl" target="_blank"></a>
然后用javascript单击它,如下所示
document.getElementById("anchorID").click();
#2楼
例如:
$(document).on('click','span.external-link',function(){
var t = $(this),
URL = t.attr('data-href');
$('<a href="'+ URL +'" target="_blank">External Link</a>')[0].click();
});
工作示例 。
#3楼
window.open(
'https://support.wwf.org.uk/earth_hour/index.php?type=individual',
'_blank' // <- This is what makes it open in a new window.
);
#4楼
您可以使用window.open('https://support.wwf.org.uk/earth_hour/index.php?type=individual');在新窗口中打开它window.open('https://support.wwf.org.uk/earth_hour/index.php?type=individual'); 。 如果要在新选项卡中打开它,请在两个选项卡中打开当前页面,然后允许脚本运行,以便同时获取当前页面和新页面。
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3169435