0

私は自分のウェブサイトを持っています

www.aplicatii-iphone.ro

そしてもう一つ

localhost の page.html

<html>
<head>
<title>Object References across Iframes</title>

<script type="text/javascript">

window.onload = function(){
    var form = document.getElementById('testForm');
    form.testBtn.onclick = sendData;
}

function notify() {
    //alert('iframe loaded');
    var iframeEl = document.getElementById('ifrm');
    if ( iframeEl && iframeEl.parentNode && document.createElement ) {
        var newTxt = document.createTextNode('The iframe has loaded and your browser supports it\'s onload attribute.');
        var newPara = document.createElement("p");
        newPara.className = 'demo';
        newPara.appendChild(newTxt);
        iframeEl.parentNode.insertBefore(newPara, iframeEl);
    }
}

function sendData() { // to form inside iframed document
    // frames array method:
   // window.frames['ifrm'].document.forms['ifrmTest'].elements['display'].value = this.form.testEntry.value;
    var ifrm = document.getElementById('ifrm');
    var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document;
    var form = doc.getElementById('search-input'); // <------<< search input
    form.display.value = this.form.testEntry.value;
    form.submit();
}

// test in iframed doc
var counter = 0;

</script>
</head>
<body>

<form id="testForm" action="#">
<p><input type="text" name="testEntry" size="30" value="[enter something]" /> <input name="testBtn" type="button" value="Click Me" /></p>
</form>

<iframe name="ifrm" id="ifrm" src="http://www.aplicatii-iphone.ro" onload="notify()" width="900">Sorry, your browser doesn't support iframes.</iframe>

</body>
</html>

そしてボタンを押すたびにwww.aplicatii-iphone.roClick Meの状態がユーザーが「testEntry」に書かれたその値をiframeの外から検索したような状態になってほしい。

私はそこで何かを試しました...しかし、私はそれを理解することができません...何か助けてください?

ここから例を取りましたhttp://www.dyn-web.com/tutorials/iframes/refs.php

4

2 に答える 2

3

最新のブラウザーを使用していることがわかっている場合は、postMessage を使用してフレーム間の通信を行うことができます。ここに良い記事があります:http://ajaxian.com/archives/cross-window-messaging-with-html-5-postmessage

従来のブラウザをサポートする必要がある場合は、Google Closure の CrossPageChannelオブジェクトを使用してフレーム間の通信を行うことができます。

于 2012-05-29T16:57:28.577 に答える
3

残念ながら、 Same Orgin ポリシーにより、これは不可能です。
-valueを変更するdocument.domainと、サブドメインをメインドメインに接続しようとする場合にのみ役立ちます。

編集 同じウェブサイトのページを使用して同じ起源の問題を回避する場合、これはうまくいくはずです:

window.frames['ifrm'].document.getElementById("search-input").value = document.getElementsByName("testEntry")[0].value;
window.frames['ifrm'].document.getElementById("cse-search-box").submit();
于 2012-05-29T16:51:51.777 に答える