Link hreflang attribute

Definition and Usage

hreflang Sets or returns the language code of the linked document.

The hreflang attribute will not be displayed as any special content in any mainstream browser. However, it can be used by search engines or scripts.

Tip:To view all available language codes, please visit ourLanguage Code Reference Manual.

See also:

HTML Reference Manual:HTML <link> hreflang 属性

HTML Reference Manual:HTML <link> 标签

Example

Example 1

Return the language code of the linked document:

var x = document.getElementById("myLink").hreflang;

Try it yourself

Example 2

Change the language code of the linked document:

document.getElementById("myLink").hreflang = "en-us";

Try it yourself

Syntax

Return hreflang attribute:

linkObject.hreflang

Set hreflang attribute:

linkObject.hreflang = languagecode

属性值

描述
languagecode 规定被链接文档的语言代码。

技术细节

返回值: 字符串值,表示被链接文档的语言代码。

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持