Take the 2-minute tour ×

Alright. I basically want to create an iframe on my website which leads to my other website.

On my iFramed website I have a form with a Text Field and a Submit button. I would like to insert some text to the Text Field and then Click on the submit button WHEN I click on a button at Site A (the one which contains the iframe).

Is it possible in some way?

I have tried the follwoing but it doesn't seems to work:

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

<iframe name="iframeAB" src ="index.html" id="qab" width="100%" height="210" style="border:1px solid #009ee0">
    Your browser doesn't handle iframes
<input type="button" value="Go" onclick="top.frames['iframeAB'].window.document.body.getElementById('text_field').value='test successful';"/>
<a href="#" onclick="insertTxt();">test</a>
share|improve this question
Unless on same domain, port and protocol, not possible –  mplungjan Dec 29 '13 at 6:42
add comment

2 Answers

Try using window.frames["iframeAB"].documentContent instead of window.frames["iframeAB"].document

share|improve this answer
add comment

Try this using jQuery:

// Include the jQuery file inside the head tag
// Download the latest version, this is in the jQuery website

// 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...

share|improve this answer
I'm not so good with jQuery. Can you please tell me how can I call this function? Or I should just paste this code to the head between Javascript tags and it will work? –  Radical_Activity Apr 23 '13 at 11:38
I have updated the code. Put it inside the head tag. –  palaѕн Apr 23 '13 at 12:51
It should work even for other domain? I mean Site A is on my domain and Site B (the iFramed one) in another domain. Would that work in that case? –  Radical_Activity Apr 23 '13 at 12:58
I hope so. Give it a try... –  palaѕн Apr 23 '13 at 13:02
It doesn't seems to work at all :( I have tired this by creating an Index file and create a file which contains the form itself, but it doesn't seens to do anything. –  Radical_Activity Apr 23 '13 at 14:24
add comment

Your Answer


