質問
い問題を呼び出すJavaScript機能 iframe
親からページです。ここでは私のページ:
mainPage.html
<html>
<head>
<title>MainPage</title>
<script type="text/javascript">
function Reset()
{
if (document.all.resultFrame)
alert("resultFrame found");
else
alert("resultFrame NOT found");
if (typeof (document.all.resultFrame.Reset) == "function")
document.all.resultFrame.Reset();
else
alert("resultFrame.Reset NOT found");
}
</script>
</head>
<body>
MainPage<br>
<input type="button" onclick="Reset()" value="Reset"><br><br>
<iframe height="100" id="resultFrame" src="resultFrame.html"></iframe>
</body>
</html>
resultFrame.html
<html>
<head>
<title>ResultPage</title>
<script type="text/javascript">
function Reset()
{
alert("reset (in resultframe)");
}
</script>
</head>
<body>
ResultPage
</body>
</html>
(知っている document.all
なおこのページのみ閲覧できます。IEを社内とは思わないことになる問題)
私はを押してリセットボタンを取得しま"resultFrame見つかり"および"resultFrame.リセットが見つかりませんでした".することができる基準のフレームができない電話機能のフレームこの理由は何でしょうか?
解決
用途:
document.getElementById("resultFrame").contentWindow.Reset();
アクセスのリセット機能のiframe
document.getElementById("resultFrame")
このiframeコードで、 contentWindow
このwindowオブジェクトのiframe.ば、子窓されていることをご確認くださいjavascriptメディアです。
も こちらの 特に答えbobince.
他のヒント
の代わりに、フレームから書くのフレーム窓からのオブジェクトです。
上記の例ではこの設定を変更:
if (typeof (document.all.resultFrame.Reset) == "function")
document.all.resultFrame.Reset();
else
alert("resultFrame.Reset NOT found");
へ
if (typeof (window.frames[0].Reset) == "function")
window.frames[0].Reset();
else
alert("resultFrame.Reset NOT found");
問題は、その範囲は、javascriptのiframeが露出しないのDOM要素のiframe.みwindowオブジェクトは、javascriptのスコーピングのための情報のフレームに。
とても頑健性:
function getIframeWindow(iframe_object) {
var doc;
if (iframe_object.contentWindow) {
return iframe_object.contentWindow;
}
if (iframe_object.window) {
return iframe_object.window;
}
if (!doc && iframe_object.contentDocument) {
doc = iframe_object.contentDocument;
}
if (!doc && iframe_object.document) {
doc = iframe_object.document;
}
if (doc && doc.defaultView) {
return doc.defaultView;
}
if (doc && doc.parentWindow) {
return doc.parentWindow;
}
return undefined;
}
や
...
var el = document.getElementById('targetFrame');
var frame_win = getIframeWindow(el);
if (frame_win) {
frame_win.reset();
...
}
...
電話
window.frames['resultFrame'].Reset();
objectframe.contentWindow.Reset()
必要なものを参考にトップレベル要素のフレームです。
第一条件とニーズを満たするのは親会社のiframeに属することが望。それができたら、子どもを呼び出すの親を用います。オープナー方式との親会社で同一の子として上記の
アクセスすresultFrameを書きします。すべてのみ引きとしてHTML要素ではなく、窓枠がつきます。するとともに、同誌掲載号の注目するフレームの火イベントをこの"自己参考にする。
置き換え:
document.all.resultFrame.Reset();
:
window.frames.resultFrame.Reset();
または:
document.all.resultFrame.contentWindow.Reset();
できない場合は利用で直接出てしまったこのエラー:遮断フレームの起源"http://www..com"からのアクセスのクロス由来のフレーム。利用できる postMessage() く機能を利用します。