在新选项卡/窗口/弹出窗口中打开外部网站 [英] Opening an external website in a new tab/window/popup
问题描述
我知道点击:
< a href =http://www.example.com> ;点击此处< / a>
会退出当前页面并转到此地址,并且
< a href =http://www.example.comtarget =_ blank>点击此处< / a>
会在新标签中打开 (Chrome和Firefox中的默认行为)。
但如何让按钮点击它可以在新浏览器窗口中打开外部网站,可能700x500px?(例如,如果您在Chrome浏览器菜单中使用 New window )
不能用纯HTML做到 - 要达到你需要JavaScript的效果。 .example.comonclick =window.open('http://www.example.com','newwindow',
'width = 700,height = 500');
return false;>点击此处< / a>
然而,这个解决方案很容易被弹出窗口阻止。
正如 @Rob M. 所建议的那样,这里您可以阅读关于 window.open()
。
I know that clicking on:
<a href="http://www.example.com">Click here</a>
would quit the current page and go to this address, and that
<a href="http://www.example.com" target="_blank">Click here</a>
would open it in a new tab (default behaviour in Chrome and Firefox).
But how to have a button such that clicking on it would open the external website in a new browser window, possibly 700x500px? (like if you do New window in Chrome menu)
You cannot do that with pure HTML - to achieve the result you need JavaScript.
<a href="http://www.example.com" onclick="window.open('http://www.example.com',
'newwindow',
'width=700,height=500');
return false;">Click here</a>
However, this solution is vulnerable to be pop-up blocked.
As @Rob M. suggested, here you can read everything about window.open()
.
这篇关于在新选项卡/窗口/弹出窗口中打开外部网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!