Extracting the XHTML "lang" parameter.

L

lucanos

Hi All,

I am toying with the idea of making a GreaseMonkey script, or similar
(depending on how far out of my comfort zone I am willing to venture),
which would translate a page automatically.

In order to trigger that script and pass the correct variable to the
translator, I am looking for a way to extract certain details from the
current page.

One of the pages I am looking at is XHTML, and I am wanting to extract
the "lang" (or maybe the "xml:lang") from the page.
In the source it is shown like this:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"
dir="ltr">

How would I reference that in JavaScript?

Any assistance or references that you may provide would be appreciated.

Luke
 
M

Martin Honnen

One of the pages I am looking at is XHTML, and I am wanting to extract
the "lang" (or maybe the "xml:lang") from the page.
In the source it is shown like this:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"
dir="ltr">

How would I reference that in JavaScript?

It depends on whether the document is parsed by an HTML parser or an XML
parser, if it is parsed by an HTML parser then
document.documentElement.getAttribute('lang')
document.documentElement.getAttribute('xml:lang')
should do.
If it is parsed by an XML parser then for the lang attribute it should be
document.documentElement.getAttribute('lang')
too, for the xml:lang attribute you need getAttributeNS as in the following

document.documentElement.getAttributeNS('http://www.w3.org/XML/1998/namespace',
'lang')


That way in an XHTML document served as application/xhtml+xml both
Mozilla (tested with 1.7) as well as Opera (tested with 8.50) give the
value of the xml:lang attribute.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top