問題点:
2年前までは Firefox で動いていた単純な javascript によるページ内情報の読み込み方法が
ここ最近になって、作動停止するようになってしまいました。
その内容とは、オフラインでローカルファイルのHTML上で
iframe 内の情報を親ページから読み込むだけの
非常に初歩的な操作です。
異常動作を呈するブラウザ:
Firefox 78
IE11 では、まだ部分的に作動する HTML構文を掲載します。
html
1 2<body> 3 4 <INPUT type="button" value="01: Read the frame content using => (frameID).contentDocument.getElementById" onClick="readChild01()" > 5<br><br> 6 7 <INPUT type="button" value="02: Read the frame content using => document.getElementById(-iframe-).contentWindow.document.getElementById" onClick="readChild02()" > 8<br><br> 9 <INPUT type="button" value="03: Read the frame content using => split form of the above" onClick="readChild03()" > 10<br><br> 11 <INPUT type="button" value="04: Read the frame content using => document.getElementById(-iframe-).contentDocument.getElementById" onClick="readChild04()" > 12 13<br><br> 14 15<iframe id="frame01" src="childWindow.html" width="500" height="150" > 16</iframe> 17 18<br><br><br><br> 19 20<textarea id= "parentText03" > 21empty 22</textarea> 23<br><br><br><br> 24Error message by Firefox 78.0 25<br><br> 26<pre> 2701: 28frame01.contentDocument is null 29 3002: 31Uncaught DOMException: Permission denied to access property "document" on cross-origin object 32 3303: 34Uncaught DOMException: Permission denied to access property "document" on cross-origin object 35 3604: 37contentDocument is null 38 39</pre> 40 41<br> 42 43</body>
iframe 内に読み込むローカルファイル (offline):
file name: childWindow.html
html
1 2<!-- frame page file name: childWindow.html --> 3 4<body> 5 6<br> 7<INPUT id= "frameText02" 8 value="This is a sample script inside the frame." 9 size=70 > 10<br> 11<br> 12<br> 13<br> 14 15frame 16</body> 17
javascript
1 2 3function readChild01() { 4 5 var fr01Txt = frame01.contentDocument.getElementById("frameText02").value ; 6 7 document.getElementById( "parentText03" ).value = fr01Txt ; 8 9// Error: frame01.contentDocument is null 10} 11 12 13function readChild02() { 14 15 var fr01Txt = 16 document.getElementById( "frame01" ).contentWindow.document.getElementById("frameText02").value ; 17 18 document.getElementById( "parentText03" ).value = fr01Txt ; 19 20/* ERROR: 21Uncaught DOMException: Permission denied to access property "document" on cross-origin object 22 */ 23} 24 25 26function readChild03() { 27 28 var fr01ELM = document.getElementById( "frame01" ) ; 29 30 var fr01Txt = fr01ELM.contentWindow.document.getElementById("frameText02").value ; 31 document.getElementById( "parentText03" ).value = fr01Txt ; 32 33/* ERROR: 34Uncaught DOMException: Permission denied to access property "document" on cross-origin object 35 */ 36 37} 38 39function readChild04() { 40 41 var fr01Txt = 42 document.getElementById( "frame01" ).contentDocument.getElementById("frameText02").value ; 43 44 document.getElementById( "parentText03" ).value = fr01Txt ; 45 46// ERROR: contentDocument is null 47 48} 49 50
問題点2:
数年前まで可能であった、
(frame-id).contentDocument.getElementById()
による読み込みが、今のブラウザではエラー扱いがされており
作動不能
問題点3:
offline 状態でHD上の同一フォルダー内に置かれている
ローカルファイルの親ページと子ページをブラウザが
iframe 内に読み込むことが
当たり前にできていながら
そこに表示されている内容を
javascript で 親ページから読ませようとすると
Uncaught DOMException: Permission denied to access property "document" on cross-origin object
というエラーが発生
質問内容:
同一フォルダ内に置かれているローカルファイルの親ページと子ページを
iframe を用いて表示している際に
どのような方法を用いれば、
iframe 内の .innerHTML または .value を
以前のように親ページから読み込むことができるでしょうか?

回答1件
あなたの回答
tips
プレビュー