如何在iframe中引用iframe

时间:2016-12-28 05:50:24

标签: jquery html css iframe

我想引用另一个iframe中的iframe

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="playButton">Play</div>
<div class="flex-active-slide">
<iframe src=""> <!--But refering this-->
  #document
   <html>
      <body>
        <iframe src=""><!--want to refer this iframe -->
          #document
           <html>
              <body>

              </body>
           </html>
        </iframe>
      </body>
   </html>
 <iframe>
   </div>

  jQuery(document).ready(function($){
  $(".playButton").on('click',function(){
      $(".flex-active-slide iframe")[0].src += "&autoplay=1";
    });
  });

2 个答案:

答案 0 :(得分:0)

加载后,使用contents()进入第一帧窗口:

$('iframe').on('load', function(){
  var $secondFrame = $(this).contents().find('iframe');
      $secondFrame.attr('src', someUrl)    
})

答案 1 :(得分:0)

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>

您可以使用“i2”类访问iframe:

var l1 = $(".flex-active-slide .i1")[0];
$(l1.contentDocument).find("iframe.i2");