By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Extracting the XHTML "lang" parameter.

P: n/a
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

Sep 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


lu*****@gmail.com wrote:

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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.