0
    <html dir="LTR">
    <head></head>
    <body> 
      <iframe id="id_description_iframe" class="rte-zone" height="200" frameborder="0" title="description">
        <html>
          <head>
            <script>
              alert('document.querySelector("html").dir');
            </script>
          </head>
          <body class="frameBody">
            test<br/>
          </body>
        </html>
      </iframe>
    </body>
  </html>

What I need is the value of dir in html that is "LTR".

I tried "document.querySelector("html").dir" from inside iframe's code and it returns "" as it looks for the second html tag.

Vijayendra Mudigal
  • 4,245
  • 1
  • 14
  • 12

1 Answers1

1

Since it's in a different document, you can't find it starting with document.

But assuming your iframe and its parent are in the same origin, you can access it via parent.document.querySelector('html').dir or more directly parent.document.documentElement.dir (as documentElement in an HTML document is the html element):

alert(parent.document.documentElement.dir);

You wouldn't have access to that if the iframe and its parent aren't in the same origin.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875