Search code examples
javascripthtmlframesframeset

Interacting with Separate Frames


I am setting up an HTML page with a frameset that has 2 frames. I would like to initiate an action on one frame which would modify something in the other frame. For example, clicking a button on frame 1 would change the innerHTML of an element with an id on frame 2.

How would I go about doing this?

Thanks


Solution

  • You can trigger the following javascript upon some event in frame 1:

    window.parent.frame2.document.getElementById('element_id').innerHTML = 'new content';
    

    Assuming frame 2 element has a name of "frame2" and the element you want to modify has an id of "element_id".