The hreflang
property sets or gets the language code of the linked document.
hreflang |
Yes | Yes | Yes | Yes | Yes |
Return the hreflang property.
var v = linkObject.hreflang
Set the hreflang property.
linkObject.hreflang=languagecode
Value | Description |
---|---|
languagecode | Set the language code of the linked document |
A String type value representing the language code of the linked document.
The following code shows how to change the language code of the linked document.
<!DOCTYPE html>
<html>
<head>
<link id="myLink" href="http://java2s.com" hreflang="en">
</head><!-- w ww. ja v a 2 s . c o m-->
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myLink").hreflang = "en-us";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the language code of the linked document.
<!DOCTYPE html>
<html>
<head>
<link id="myLink" href="http://example.com" hreflang="en">
</head><!--from ww w. j a va 2 s . c o m-->
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myLink").hreflang;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: