在新标签/窗口/弹出窗口中打开外部网站

问题描述 投票:1回答:1

我知道点击:

<a href="http://www.example.com">Click here</a>

将退出当前页面并转到此地址

<a href="http://www.example.com" target="_blank">Click here</a>

会在新标签页中打开它(Chrome和Firefox中的默认行为)。

但如何点击一个按钮就可以在新的浏览器窗口中打开外部网站,可能是700x500px? (就像你在Chrome菜单中执行新窗口一样)

javascript html browser popup popupwindow
1个回答
3
投票

你不能用纯HTML做到这一点 - 为了达到你需要JavaScript的结果。

<a href="http://www.example.com" onclick="window.open('http://www.example.com', 
                                         'newwindow', 
                                         'width=700,height=500'); 
              return false;">Click here</a>

但是,此解决方案很容易被弹出窗口阻止。

正如@Rob M.所说,here你可以阅读有关window.open()的一切。

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