how to refer iframe within iframe

前端 未结 2 1114
温柔的废话
温柔的废话 2021-01-26 20:21

I want to refer iframe which is inside another iframe


<         


        
相关标签:
2条回答
  • 2021-01-26 21:00

    Use contents() to get inside first frame window once it has loaded:

    $('iframe').on('load', function(){
      var $secondFrame = $(this).contents().find('iframe');
          $secondFrame.attr('src', someUrl)    
    })
    
    0 讨论(0)
  • 2021-01-26 21:03
    Consider this:
    
    <div class="flex-active-slide">
    <iframe class="i1" src=""> <!--But refering this-->
      #document
       <html>
          <body>
            <iframe class="i2" src=""><!--want to refer this iframe -->
              #document
               <html>
                  <body>
    
                  </body>
               </html>
            </iframe>
          </body>
       </html>
     <iframe>
       </div>
    

    You can access iframe with class "i2" as:

    var l1 = $(".flex-active-slide .i1")[0];
    $(l1.contentDocument).find("iframe.i2");
    
    0 讨论(0)
提交回复
热议问题