HTMLLinkElement:hreflang 属性
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
HTMLLinkElement
接口的 hreflang
属性用于指示页面的语言和地理定位。浏览器可以利用这一提示来选择更合适的页面或提高搜索引擎优化。
它反映 <link>
元素的 hreflang
属性,如果没有 hreflang
属性,则该属性的值为空字符串(""
)。
值
包含语言标签的字符串,如果没有 hreflang
属性,则为空字符串(""
)。
示例
html
<link
rel="alternate"
href="www.example.com/fr/html"
hreflang="fr"
type="text/html"
title="法语 HTML 页面" />
<p class="tag"></p>
css
.tag {
margin-left: 20px;
font: bold;
font-size: 24px;
}
js
const myLink = document.querySelector("link");
const pTag = document.querySelector(".tag");
pTag.textContent = myLink.hreflang;
结果
规范
Specification |
---|
HTML> # dom-link-hreflang> |
浏览器兼容性
Loading…