Html 获取锚标签以在新窗口中打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25036935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get anchor tag to open in new window
提问by SAF
Is there a way to get anchor tags to open in a new window instead of the current one?
有没有办法让锚标签在新窗口而不是当前窗口中打开?
<a href="my_link">Link</a>
Thanks
谢谢
采纳答案by prakashstar42
Use jQuery/javascript to open in new window
使用 jQuery/javascript 在新窗口中打开
$('a').click(function(){
window.open('http://google.com')
});
回答by Quentin
Set the target
attribute to _blank
.
将target
属性设置为_blank
。
You have no control over what sort of new "window" the browser will open it in. It might be an actual window, it might be a tab, it might be overridden and forced to the same window.
您无法控制浏览器将在哪种新“窗口”中打开它。它可能是一个实际的窗口,也可能是一个选项卡,它可能被覆盖并强制进入同一窗口。
It is, however, a bad idea, so don't do it, really, please don't.
回答by Gopi P
you no need to write such long javascript to do with your requirement. Just set target attribute to _blank in your anchir tag itself. whenever a user click on that link it will open in new tab. sample tag is as follow
您无需编写这么长的 javascript 来满足您的要求。只需在您的 anchir 标签中将 target 属性设置为 _blank 即可。每当用户单击该链接时,它将在新选项卡中打开。示例标签如下
<a href="www.google.com" target="_blank">Google</a>
Hope this helps you
希望这对你有帮助
NOTE: For Security reason
注意: 出于安全原因
回答by Mohammad Fareed
This will work but its pure javascript
这会起作用,但它是纯 javascript
<a href="http://www.snopzer.com" onclick="window.open(this.href, 'Snopzer',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" >Open Link</a>
回答by Darren Gomez
The easiest way is to do:
最简单的方法是:
<a href="https://www.google.com/" target="new">Google</a>
This will open whatever the link given in a new tab.
这将打开新选项卡中给出的任何链接。