0

大丈夫。私は基本的に、他のウェブサイトにつながる自分のウェブサイトに iframe を作成したいと考えています。

私の iFramed Web サイトには、テキスト フィールドと [送信] ボタンのあるフォームがあります。テキスト フィールドにテキストを挿入し、サイト A (iframe を含むボタン) のボタンをクリックしたときに送信ボタンをクリックしたいと思います。

何らかの方法で可能ですか?

次のことを試しましたが、うまくいかないようです:

<script type="text/javascript">
    function insertTxt() {
        var textstring = "test successful";
        window.frames["iframeAB"].document.documentElement.getElementsByTagName("textarea")[0].value = textstring;
    }
</script>

<iframe name="iframeAB" src ="index.html" id="qab" width="100%" height="210" style="border:1px solid #009ee0">
    Your browser doesn't handle iframes
</iframe>
<input type="button" value="Go" onclick="top.frames['iframeAB'].window.document.body.getElementById('text_field').value='test successful';"/>
<a href="#" onclick="insertTxt();">test</a>
4

3 に答える 3

0

jQueryを使用してこれを試してください:

// Include the jQuery file inside the head tag
// Download the latest version, this is in the jQuery website
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script>
// Then call the code inside ready method like this
$(document).ready(function () {
    // Get the iFrame jQuery Object
    var $MyFrame = $("iframe[name='iframeAB']");

    // You need to wait for the iFrame content to load first
    // So, that the click events work properly
    $MyFrame.load(function () {
        var frameBody = $MyFrame.contents().find('body');

        // Find the textarea by id
        var textarea = frameBody.find('#text_field');

        // Set the value here...
        textarea.val(textstring);
    });
});

</script>
于 2013-04-23T11:33:33.527 に答える
0

window.frames["iframeAB"].documentContentの代わりに使用してみてくださいwindow.frames["iframeAB"].document

于 2013-04-23T11:32:17.020 に答える
0

この解決策を試すことができます:

JQueryを使用しています

あなたのHTML

<iframe name="iframeAB" src ="index.html" id="qab" width="100%" height="210" style="border:1px solid #009ee0">
    Your browser doesn't handle iframes
</iframe>
<input type="button" value="Go" onclick="top.frames['iframeAB'].window.document.body.getElementById('text_field').value='test successful';"/>
<a href="#" onclick="insertTxt();">test</a>

JS ファイルの insertTxt() メソッド

$("#qab").ready(function() {
    $("#qab").contents().find("body").find('textarea').val('Test Successful');
});
于 2014-09-27T17:51:48.137 に答える