Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you do <code>$(response)</code> on the response text, the <code>html</code> element gets dropped by most (if not all) browsers. To look at it, I see two options:</p> <ol> <li><p>Process the text as text. Not ideal, but it's not that complicated to parse the attributes on the <code>&lt;html&gt;</code> tag. For instance, this should extract the <code>lang</code> attribute barring the unusual:</p> <pre><code>var regex = /&lt;\s*html\s[^&gt;]*lang\s*=\s*["']?([A-Za-z0-9\-]+)/i; var matches = regex.exec(str); console.log(matches[1]); </code></pre> <p><a href="http://jsbin.com/udezox" rel="nofollow">Live example</a> | <a href="http://jsbin.com/udezox/edit" rel="nofollow">Live source</a></p> <p>Usual caveat: HTML is not a <a href="http://en.wikipedia.org/wiki/Regular_language" rel="nofollow">regular language</a>, so you can't reliably parse it with regular expresions. Sometimes a well-tuned regex can extract bits of information from HTML text, and those can be "good enough" when they're rigorously tested with the expected input data, but just beware that they cannot work reliably against all possible HTML source texts.</p></li> <li><p>Rather than using <code>$.get</code>, create a hidden iframe and assign <code>page</code> to it as its <code>src</code>. Then use <code>iframe.contentDocument.documentElement</code> to access the <code>html</code> element, and use <code>getAttribute</code> to read its <code>lang</code> attribute.</p> <p>That might look something like this:</p> <p><a href="http://jsbin.com/ugesoh" rel="nofollow">Live copy</a> | <a href="http://jsbin.com/ugesoh/edit" rel="nofollow">Live source</a> | <a href="http://jsbin.com/imeqij/edit" rel="nofollow">Source of page being loaded</a></p> <pre><code>display("Loading the iframe..."); var $iframe = $("&lt;iframe&gt;"); $iframe .css({ position: "absolute", left: "-10000px" }) .bind("load", function() { var doc = $iframe[0].contentDocument, html = doc &amp;&amp; doc.documentElement, lang = html &amp;&amp; html.getAttribute("lang"); if (lang) { display("&lt;code&gt;lang = " + lang + "&lt;/code&gt;"); $iframe.remove(); // Or not, as you prefer } }) .appendTo(document.body); $iframe[0].src = "http://jsbin.com/imeqij"; </code></pre> <p>(I've had to be somewhat defensive there because JSBin wraps our page in a frame of its own.)</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload