在页面加载的新标签页中打开特定链接 [英] Open specific link in new tab on pageload

查看:66
本文介绍了在页面加载的新标签页中打开特定链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我从这里得到了一个解决方案,该解决方案是如何在页面加载时自动打开另一个链接.我得到了这段代码来做到这一点

  window.setTimeout(& quot; autoClick()& quot; 2000);//2秒延迟函数autoClick(){var linkPage = document.getElementById(&#39; dynLink&#39;).href;window.location.href = linkPage;}</script> 

dynLink 在正文中用作链接标记中的 target ="_ blank" .但这正在同一选项卡中加载所需的页面.不在新标签页中.

我希望当此自动页面加载单击id = dynLink的链接时,页面在新选项卡中打开,然后在同一选项卡中加载.

我的意思是新选项卡-不是新窗口.

期待一些可行的解决方案.谢谢!

解决方案

您可以尝试以下操作:

  var newTab = window.open('http://google.at','_blank');newTab.location; 

这是小提琴: http://jsfiddle.net/70kdacL4/310/

针对您的具体情况:

HTML:

 < a id ="link" href ="http://www.google.at" target ="_ blank"> TestLink</a> 

JavaScript:

  $(document).ready(function(){window.setTimeout(function(){var link = document.getElementById("link").href;var newTab = window.open(link,'_blank');},5000);}); 

如果使用弹出窗口阻止程序,请小心.弹出窗口阻止程序可以阻止选项卡打开.

这是小提琴: http://jsfiddle.net/qm9ss6s4/4/

Previously, I got a solution from here on how to open another link automatically on page load. I got this code to do that

window.setTimeout(&quot;autoClick()&quot;, 2000); // 2 seconds delay

function autoClick() {
var linkPage = document.getElementById(&#39;dynLink&#39;).href;
window.location.href = linkPage;
}
</script> 

dynLink is used in the body as target="_blank" within link tag. But this is loading the desired page within the same tab. Not in a New Tab.

I want when this auto page load clicks the link with id=dynLink, the page opens in a new tab then to load in the same tab.

And I really means New TAB - NOT NEW WINDOW.

Looking forward to some working solution. Thanks!

解决方案

You can try this:

 var newTab = window.open('http://google.at', '_blank');
 newTab.location;

Here is the fiddle: http://jsfiddle.net/70kdacL4/310/

For your specific case:

HTML:

<a id="link" href="http://www.google.at" target="_blank">TestLink</a>

JavaScript:

$(document).ready(function(){
    window.setTimeout(function(){
        var link = document.getElementById("link").href;
        var newTab = window.open(link, '_blank');
    }, 5000);
});

Be careful if you use a popup blocker. A popup blocker can prevent the tab from beeing opened.

Here is the fiddle: http://jsfiddle.net/qm9ss6s4/4/

这篇关于在页面加载的新标签页中打开特定链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆