javascript 如何使用 CSS 在新选项卡/窗口中打开链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27915253/
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
How to open links in a new tab/window using CSS?
提问by Trey Shaffer
Is it possible to style the hyperlink tag in CSS in such a way that when a link is clicked it opens it in a new tab or window? I know the solution in HTML and JavaScript/jQuery, yet is it possible to specify this attribute using a stylesheet? Also note that this question is important because it could possibly save me many keystrokes and code clutter. Thanks for your mind and time. =)
是否可以在 CSS 中设置超链接标签的样式,以便在单击链接时在新选项卡或窗口中打开它?我知道 HTML 和 JavaScript/jQuery 中的解决方案,但是否可以使用样式表指定此属性?另请注意,这个问题很重要,因为它可能会为我节省许多按键和代码混乱。感谢您的心意和时间。=)
HTML:
HTML:
target="_blank"
jQuery/JavaScript:
jQuery/JavaScript:
window.open($(this).attr("href"), '_blank', 'modal=yes');
Css:
css:
.class a {
???
}
回答by imnancysun
Seems it's not supported by current browsers, refer to http://www.w3schools.com/cssref/css3_pr_target-new.asp
似乎当前浏览器不支持它,请参阅http://www.w3schools.com/cssref/css3_pr_target-new.asp