HTML ページに 2 レベルの親子 iframe 階層があります。何らかの操作のために、親ウィンドウ ドキュメントのオブジェクトを子ドキュメントに取得したいと考えています。主に Google Chrome を使用しています。
parent.document は、Google Chrome では「未定義」になりますが、Mozilla では問題なく動作します。キャッチは何ですか?
参考までに、問題を示す 3 つのファイルの内容を以下に示します。
最初のファイル: 'one.html'
<html>
<head>
</head>
<body>
<input type="hidden" id="one_1" name="one_1" />
<iframe id="one" name="one" src="two.html">
</body>
</html>
2 番目のファイル:「two.html」
<html>
<head>
</head>
<body>
<input type="hidden" id="two_1" name="two_1" />
<iframe id="two" name="two" src="three.html">
</body>
</html>
3 番目のファイル:「three.html」
<html>
<head>
<script type="text/javascript">
function callme() {
alert(parent.document)
alert(top.document)
}
</script>
</head>
<body>
<input type="hidden" id="three_1" name="three_1" />
<button id="click" name="click" onclick="return callme()">Click Me</button>
</body>
</html>
「one.html」が Google Chrome で開かれていると仮定すると、「クリックしてください」ボタンをクリックすると、2 つの連続する警告ボックスが「未定義」の値で表示されます。Mozilla で「one.html」を開くと、2 つの「objectHTMLDocument」値の警告ボックスが表示されます。
[Click Me] ボタンをクリックしたときのコンソール メッセージの下に表示されます。
Unsafe JavaScript attempt to access frame with URL file:///C:/Users/user/Desktop/two.html from frame with URL file:///C:/Users/user/Desktop/three.html. Domains, protocols and ports must match.
three.html:6
callme three.html:6
onclick three.html:13
Unsafe JavaScript attempt to access frame with URL file:///C:/Users/user/Desktop/one.html from frame with URL file:///C:/Users/user/Desktop/three.html. Domains, protocols and ports must match.
three.html:7
callme three.html:7
onclick three.html:13
前もって感謝します。