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

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

这是我的代码:

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

当你点击它时,它会带你到雅虎,但它不会打开一个新窗口?

html hyperlink window.location
3个回答
128
投票
<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> 

也检查这个

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