Reputation: 853
I am trying to get the lang value from the HTML tag, but the current JavaScript I am using doesn't work.
This is the HTML code I am trying to access:
<html lang="it-IT">
And the Javascript
if(navigator.appName == 'Netscape')
{
langType = navigator.language;
}
else
{
langType = navigator.browserLanguage;
}
but in testing I still get the value "EN-us"
Can anyone help?
Thanks!
Upvotes: 24
Views: 37609
Reputation: 169593
Use
document.documentElement.lang
As Rob has commented, your code gets the browser's language and not the document's.
Upvotes: 74
Reputation: 6981
try this
var language = document.getElementsByTagName("html")[0].getAttribute("lang");
I haven't tried it, but it should work.
Upvotes: 6