Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用javascript计算多个iframe的加载时间_Php_Javascript - Fatal编程技术网

Php 用javascript计算多个iframe的加载时间

Php 用javascript计算多个iframe的加载时间,php,javascript,Php,Javascript,首先,我为我拥有的每个url创建一个iframe: $url = array(); $url[] = 'example1.com'; $url[] = 'example2.com'; foreach($url as $u){ echo '<div class="frame_container"> <iframe "width="200" height="200" id="myiframe" src="http://www.'.$u.'"> &

首先,我为我拥有的每个url创建一个iframe:

$url = array();
$url[] = 'example1.com';
$url[] = 'example2.com';

foreach($url as $u){
   echo '<div class="frame_container">
         <iframe  "width="200" height="200" id="myiframe" src="http://www.'.$u.'">  </iframe>
         <div class="loadingtime"></div>
         </div>';
}

我的问题是,所有iFrame的beforeLoad值都是相同的。每个帧的该值应该不同,因为所有FAME不会在同一时间开始加载。有什么建议吗?

使用php编写第一个div,然后使用javascript代码编写其余div

var curFrame = 1;
var totalIFrame = 2;
var url = new Array('http://www.abc.com','http://www.xyz.com');

var beforeLoad = (new Date()).getTime();
var result = 0;

function addTime() {
    var afterLoad = (new Date()).getTime();
    result += ((afterLoad - beforeLoad) / 1000);

    if(totalIFrame==curFrame){// number of iframe you will be loading
        $(this).parent().find('div.loadingtime').html(result);
    } else {
        $('.frame_container').append('<iframe  "width="200" height="200" id="myiframe" src="'+url[curFrame]+'" onload="addTime()">  </iframe>');
    }

    curFrame++;
}
var curFrame=1;
var totalIFrame=2;
var url=新数组('http://www.abc.com','http://www.xyz.com');
var beforeLoad=(新日期()).getTime();
var结果=0;
函数addTime(){
var afterLoad=(新日期()).getTime();
结果+=((后载-前载)/1000);
如果(totalIFrame==curFrame){//将要加载的iframe数量
$(this.parent().find('div.loadingtime').html(结果);
}否则{
$('.frame_container')。追加('
var curFrame = 1;
var totalIFrame = 2;
var url = new Array('http://www.abc.com','http://www.xyz.com');

var beforeLoad = (new Date()).getTime();
var result = 0;

function addTime() {
    var afterLoad = (new Date()).getTime();
    result += ((afterLoad - beforeLoad) / 1000);

    if(totalIFrame==curFrame){// number of iframe you will be loading
        $(this).parent().find('div.loadingtime').html(result);
    } else {
        $('.frame_container').append('<iframe  "width="200" height="200" id="myiframe" src="'+url[curFrame]+'" onload="addTime()">  </iframe>');
    }

    curFrame++;
}