是否可以a href在新选项卡中打开链接而不是相同的选项卡?
<a href="http://your_url_here.html">Link</a>
Run Code Online (Sandbox Code Playgroud) 我有一个"打开"按钮,用于"计算"应在新标签页中打开的链接.我尝试使用:
window.open(url, '_blank');
Run Code Online (Sandbox Code Playgroud)
但这开启了一扇新窗口.
我也尝试了以下方法:
<form id="oform" name="oform" action="" method="post" target="_blank">
</form>
...
document.getElementById("oform").action = url;
document.getElementById("oform").submit();
Run Code Online (Sandbox Code Playgroud)
仍然会打开一个新窗口,而不是新选项卡.
使用简单的<a href...>with时target='blank',链接将在新选项卡中打开.
有解决方案吗?
我可能在这里遗漏了一些简单的东西,但无论如何我都会问.我已经建立了一个打开PDF文件的链接,但它在当前标签中打开而不是新标签.我应该在HTML中使用什么代码来打开新标签来阅读PDF文件.
<div class="footer_box_content">
<div class="cleaner_h10"></div>
<p>Many thanks to everyone who cleared snow and ice during the cold spell in February.
Should Arctic conditions return, each block has a shovel and a jar of rock salt to clear the steps.
Please click more to read the full newsletter.</p>
<div class="button_01"><a href="newsletter_01.pdf">Read more</a></div>
</div>
Run Code Online (Sandbox Code Playgroud) 如何在 NextJS 的新标签页中打开链接?我试过这个:
<Link href="https://twitter.com/" passHref>
<a target="_blank">
<div className={`${dark ? styles.iconTwitterWhite : styles.iconTwitter} mr-3`} />
</a>
</Link>
Run Code Online (Sandbox Code Playgroud)
它在新标签中打开链接,但我有一条ESLint消息说:
ESLint: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles.
Run Code Online (Sandbox Code Playgroud)
还有另一种方法吗?
我为我正在做的项目创建了一个网站.在网站的内容中,有一些可以访问的外部网页链接.在用户点击其中一个链接的同时,他将被带到指定的链接,并且他将不再在当前页面上.我想要做的是当用户点击链接时,点击链接中的指定网站会显示在新标签中.这样,用户就可以保持当前页面,也可以在新选项卡上查看其他页面.
我在网上看了一下,发现这似乎很有用:
function externalLinks()
{
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++)
{
var anchor = anchors[i];
if(anchor.getAttribute("href"))
anchor.target = "_blank";
}
}
window.onload = externalLinks;
Run Code Online (Sandbox Code Playgroud)
我面临的问题是我网站的导航栏包含锚标签.所以,现在如果用户点击导航栏上的链接,它将打开一个新选项卡.我希望只有当用户点击我网站内容中的链接时才会发生这种情况.因此,如果用户单击导航栏中的链接,则不应打开新选项卡,只应将他带到指定目的地.
我已经尝试将内容添加到内容中的所有链接并使用getElementByClassName,但它仍然无法正常工作
任何人都可以帮助我