我有来自第三方开发人员的JavaScript文件。 它具备一个具备连接的连接,该连接将当前页面替换为目标页面。 我想在新标签页中打开此页面。 javascript
这是我到目前为止的内容: php
if (command == 'lightbox') { location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual"; }
谁能帮我吗? java
若是要使用location.href
以免弹出问题,能够使用空的<a>
引用,而后使用javascript单击它。 this
相似HTML url
<a id="anchorID" href="mynewurl" target="_blank"></a>
而后用javascript单击它,以下所示 spa
document.getElementById("anchorID").click();
例如: code
$(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(); });
工做示例 。 ip
window.open( 'https://support.wwf.org.uk/earth_hour/index.php?type=individual', '_blank' // <- This is what makes it open in a new window. );
您能够使用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');
。 若是要在新选项卡中打开它,请在两个选项卡中打开当前页面,而后容许脚本运行,以便同时获取当前页面和新页面。 开发