accessing elements of one iframe from another iframe

前端 未结 2 1300
星月不相逢
星月不相逢 2020-12-21 08:15

I have one parent window and two iframes in it. I am trying to access elements of one iframe from another iframe.Using the code:

function startplay(){
   va         


        
相关标签:
2条回答
  • 2020-12-21 08:35

    if you are within one of the iframes, you need to use "parent" to go to its parent, and from there reference the iframe object.

    So this should work:

    parent.nameofotheriframe.getElementById("myvideo"); 
    

    (by using getElementById you were referencing the <IFRAME> tag, not the iframe object).

    0 讨论(0)
  • 2020-12-21 08:43

    I had the same problem and solved it like this:

    My main page code:

    <div id="left">
        <iframe id="leftframe" name="leftframe" src="iframe-left.html"></iframe>
    </div>
    <div id="right">
        <iframe id="rightframe" name="rightframe" src="iframe-right.html"></iframe>
    </div>
    

    Left frame:

    <div id="DivInLeftFrame">aaa</div>
    

    Right frame:

    <input type="button" value="clickme" onclick="changeLeftFrame();">
    

    The function is:

    changeLeftFrame(){
         parent.leftframe.document.getElementById('DivInLeftFrame').innerHTML = 'bbb';
    }
    

    add the 'document' to work.

    0 讨论(0)
提交回复
热议问题