1

I'm using frame and frameset for my page. To access an element in a frame from another frame, I used this js code:

parent.frames['frame1'].document.getElementById('inputfield1');

But it just works well with Webkit. It's failed on Firefox. I think my code is wrong. How could I make it work on Firefox ?

<frameset id="fset" rows="60%,40%" frameborder="1"> 
     <frame name="frame1" src="...">
     <frame name="frame2" src="...">
</frameset>
1
  • 1
    do you have a good reason to be using frames? Commented Jan 19, 2012 at 19:36

1 Answer 1

1

Insert the following into head section of your main page.

<script language="javascript" type="text/javascript">
    function doSomething() {
        var iframe = document.getElementById('frame1');
        var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
        var your_input_field = innerDoc.getElementById(inputfield1);
    }
</script>

You can then use parent.doSomething(); inside the frames to call doSomething() of main page which can reach both frames.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.