-1

I am tring to retrieve the language value of my page, FR for French or ENG for English.

I am using document.getElementById("contentzone").innerHTML; to retrieve my data Unfortunatly the html element lang is always=en, that's why I have to find an other way...

that returns

<span style="display: none;">IE BUMPER</span>
<script type="text/javascript" src="/jquery.tools.min.jsdbx?FRv=03-10-2015_0442"></script>

How I can retrieve the src url? (/jquery.tools.min.jsbx?FRv=03-10-2015_0442) I have to retrieve "FR" which is the current language of my user, after I can parse the data and just get FR.

I've an other element on my page which displays the current language.

The html page structure is:

<html class="ltr chrome" lang="en">
<head> </head>
<body>
    <div class="my_site_layout">
    <div id="topzone">
        <div id ="conn-infos">
            <form class="conn-infos">
            <div class="login">
                FR

How I can access to this data (the string equal to FR) in Javascript? Because I think my first method with document.getElementByID to retrieve the name script is dirty.

xif
  • 343
  • 1
  • 9
  • 25
  • Take a look at http://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference – tcigrand Apr 08 '15 at 20:50

2 Answers2

1

There might be better ways to do this, but the quickest approach that comes to mind is to use getElementsByTagName.

var x = document.getElementsByTagName("html")[0].getAttribute("lang"); 
Frank Moore
  • 105
  • 1
  • 7
1

Using a combination of the previous answers, I recommend

document.documentElement.getAttribute('lang');

document.documentElement refers to the <html> element of the page. .getAttribute() is used to retrieve an HTML attribute. If the attribute were to be actual text in an element. Your question which I felt wasn't to clear mentioned that there was an element that displayed the language :

document.getElementById('element').innerHTML.trim().toUpperCase()

Possible this could work:

document.getElementsByClassName('login')[0].innerHTML.trim().split(' ')[0].toUpperCase();

getAttribute() Reference

HTML Selectors

Downgoat
  • 13,771
  • 5
  • 46
  • 69