2016-05-24 22 views
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> 

私が必要とするのは、htmlの "LTR"であるdirの値です。iframeから外部タグ属性の属性を取得する方法

私は "document.querySelector(" html ")。dir"をiframeのコードの内側から試して、2番目のhtmlタグを探すときに ""を返します。

答えて

1

これは別のドキュメントのため、documentで始まるドキュメントは見つかりません。

しかし、あなたのIFRAMEとその親が同じ起源である、あなたはparent.document.querySelector('html').dir経由でアクセスしたり、より直接的にparent.document.documentElement.dirできると仮定すると(HTML文書のdocumentElementhtml要素であるとして):

alert(parent.document.documentElement.dir); 

あなたは「wouldn iframeとその親が同じ起点にない場合、そのフレームにアクセスできます。

+0

@ゴドー:いいね。完了しました。上のいくつかの便利な追加情報は、私はそれを残しておきます。 –

関連する問題