如何使 HTML a href 超链接打开新窗口?

问题描述 投票:0回答:4

这是我的代码:

<a href="http://www.google.com" onClick="window.location.href='http://www.yahoo.com';return false;" target="_blank">test</a>

当您单击它时,它会将您带到雅虎,但不会打开新窗口?

html hyperlink window.location
4个回答
130
投票
<a href="#" onClick="window.open('http://www.yahoo.com', '_blank')">test</a>

就这么简单。

或者没有JS

<a href="http://yahoo.com" target="_blank">test</a>

5
投票

为了在新窗口中打开链接,请添加Javascript命令

onclick="window.open('text-link.htm', 'name','width=600,height=400')
<a>
标签内:

<a href="../html-link.htm" target="popup" onclick="window.open('../html-link.htm','name','width=600,height=400')">Open page in new window</a>

1
投票

当您想打开新选项卡或浏览器用户首选项设置为打开新窗口而不是选项卡时,给出的答案可能会有所帮助,因为最初的问题是关于打开新窗口而不是选项卡,这对我有用。

<a href="#" onClick='window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=800, height=600);'>test</a> 

也检查一下这个


0
投票

在窗口中打开。

在窗口中打开

© www.soinside.com 2019 - 2024. All rights reserved.