Javascript - 带有 _blank 的位置 href
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3724016/
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
Javascript - Location href with _blank
提问by Peter
is it possible to use the window.location = "http://google.de"with _blank?
可以使用window.location = "http://google.de"with_blank吗?
I dont want to use the <a href ... >at all, because it makes problems with the CSS (link-color).
我<a href ... >根本不想使用,因为它会导致 CSS(链接颜色)出现问题。
You must always insert this code and that nervs :/
您必须始终插入此代码和那个神经:/
.bone a:link { color:#FFFFFF; text-decoration: none }
.bone a:visited { color:#FFFFFF; text-decoration: none }
.bone a:hover { color:#FFFFFF; text-decoration: none }
.bone a:active { color:#FFFFFF; text-decoration: none }
.bone a:hover { color:#FFFFFF; text-decoration: none }
Thanks in advance!
提前致谢!
Peter
彼得
采纳答案by Matthew Flaschen
You probably need one CSS line:
您可能需要一行 CSS:
.bone a { color:#FFFFFF; text-decoration: none }
Technically, this will also match non-link anchor tags. But you probably want those styled the same way. I think this is cleaner than a Javascript solution.
从技术上讲,这也将匹配非链接锚标签。但是您可能希望这些样式具有相同的样式。我认为这比 Javascript 解决方案更干净。
回答by David Titarenco
Certainly, simply use window.open('http://www.example.com/', '_blank');
当然,只需使用 window.open('http://www.example.com/', '_blank');
回答by C-Mo
I assume you're looking for something like:
我假设你正在寻找类似的东西:
var w = window.open("http://google.de", "_blank");
var w = window.open("http://google.de", "_blank");
Bear in mind that it will shoot you in the foot as far as accessibility, search engine indexing, etc. go.
请记住,就可访问性、搜索引擎索引等方面而言,它会让您措手不及。
回答by thomasrutter
You must always insert this code and that nervs :/
您必须始终插入此代码和那个神经:/
You shouldn't have to insert all those. This should be enough:
你不应该插入所有这些。这应该足够了:
.bone a {
color: #FFFFFF;
text-decoration: none;
}
If you find that's not enough, you probably have a specificity problem with your CSS; that is, you've specified different link colours elsewhere in CSS with same specificity but with different colours for hover, active etc. You get around that by making the rule you want to have effect here have a higher specificity than the global rule you want it to override.
如果您发现这还不够,则您的 CSS可能存在特殊性问题;也就是说,您在 CSS 的其他地方指定了具有相同特异性的不同链接颜色,但为悬停、活动等指定了不同的颜色。您可以通过使您想要在此处生效的规则具有比您想要的全局规则更高的特异性来解决这个问题它覆盖。
Using Javascript to get around a styling problem is like buying a bicycle because you've lost your keys to your car.
使用 Javascript 解决样式问题就像买一辆自行车,因为你丢了车钥匙。
Your Javascript won't work on browsers with Javascript disabled, search engine spiders won't be able to follow it, and who knows about mobile browsers or browsers for people with disabilities.
您的 Javascript 将无法在禁用 Javascript 的浏览器上运行,搜索引擎蜘蛛将无法跟踪它,谁知道移动浏览器或残疾人浏览器。

