dongzhoulong1797 2013-06-03 17:37
浏览 25
已采纳

一个接一个地加载IFrame

Hi i am trying to load 10 iframes on a page but i want them to load one after one ...

Ex: 1st sholud load 1st and when its finish loading 2nd should start loading ... and so on

i was trying this

$i = 1;
while($i < 10){
    echo '<iframe src="/get_data.php?id='.$id.'&i='.$i.'"></iframe>';
    $i++;
    }

here there is a problem that all of them load together ... is there a way i can do this with javascript or php

  • 写回答

3条回答 默认 最新

  • duanqian8867 2013-06-03 17:57
    关注

    Based on this response Dynamically create an iframe and attach onload event to it

    Yo could do something like:

      var urls_to_load = ["http://url.com","http://url2.com","http://url3.com","http://url4.com"];
    var i = 0;
    function loadIframeAndcheckIfReady(){
        var current_url = urls_to_load[i];
        alert(i);
        frame = document.createElement('iframe');
        document.body.appendChild(frame);
        frame.setAttribute('src',current_url);
        var inter = window.setInterval(function() {
            if (frame.contentWindow.document.readyState === "complete") {
              window.clearInterval(inter);
              i++; //Now we have one url more...
              if(i < urls_to_load.length)loadIframeAndcheckIfReady(); //recursively call the function until i it's iqual to urls_to_load.length
            }
        }, 100);
    }
    loadIframeAndcheckIfReady(); //Start process
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应