對于<a>我網站上的每個單獨標簽,我都必須添加屬性"target="_blank" rel="noopener noreferrer"。然而,當我把它放在我的 CSS 樣式表中時它不起作用:
a {
target: "_blank";
rel: "noopener noreferrer";
}
它說這些屬性是未知的,這是沒有意義的,因為當我將它們放入實際標簽中時,它們會被識別并起作用。
uj5u.com熱心網友回復:
Only styling can be added with css not html attributes. Eg
You can replace below inline css style with external css
<a href="#" style="color:blue">
to
<a href="#">
a{
color: blue;
}
Whatever is there in style attribute inline can be replaced with css.
<a href="#" target="_blank">
This is target attribute and it cannot be replaced using css. Only
inline css using style can be replaced with external css.
uj5u.com熱心網友回復:
您可以嘗試使用 JavaScript。
<script>
var links = document.getElementsByTagName('a');
for (var i = links.length - 1; i >= 0; --i) {
links[i].setAttribute("target", "_blank");
links[i].setAttribute("rel", "noopener noreferrer");
}
</script>
將此插入包含鏈接的 html 檔案的底部。或者您可以將其另存為檔案并將腳本包含在 HTML 檔案的標題中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/351421.html
