简体   繁体   中英

how load iframe one by one


I need to load 6 iframes in page A.php. the contents of these 6 iframes are 6 sub pages: a1.php~a6.php. before each sub page is loaded, i need to do a ajax first (to change the database) and then load the sub pages. here is the problem. each sub page should be loaded one by one. that is to say, a2.php only can be loaded after a1.php is loaded. how to realize this function? because each sub page has a big size, so it needs a little bit long time to load. Every time, when a1.php isnot loaded totally, the ajax in a2.php is working (so the datatable has been changed).
Thank you very much if you can help me:)
JS:

function showpic(id,x,y)
{ 
    if (id==0)
    {
        var oBao = CreateHTTPObject();
        var url = "ajax.php";
        var sendstring="x="+x; 
        oBao.open("POST",url,false);
        oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        oBao.send(sendstring); 
        oBao.onreadystatechange = function () { OnReadyStateChng();};
        document.getElementById("iframe"+id).src="a.php?y=" +y;
    }
    else
    {
        var iid=id-1;
        document.getElementById("iframe"+iid).onload=function()
        {
            var oBao = CreateHTTPObject();
            var url = "ajax.php";
            var sendstring="x="+; 
            oBao.open("POST",url,false);
            oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            oBao.send(sendstring); 
            oBao.onreadystatechange = function () { OnReadyStateChng();};
            document.getElementById("iframe"+id).src="a.php?y=" +y;
        }
    }
}

PHP:

for($i=0;$i<2;$i++)
{
    for($j=0;$j<3;$j++)
    {
        $nu=$i*3+$j;
        $div="iframe".$nu;
        echo "<iframe id='$div'  height='400px' frameborder=0 ></iframe>";
        echo "<script language='JavaScript'>showpic($nu,$x,$y) ;</script></div>";
    }
}

I'm sorry but i didnt read into your code, your explanation was clear though. An ajax request always has a callback function, thats where you will get the responsetext for your request. In this anonymous callback function you can call another function which starts loading the next iframe. Just let them set the src of the frame and it will load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM