First i create an iframe for each url i have:
$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>';
}
Then i have this javascript that should calculate the time before each frame starts loading, and the time after its loaded:
$(document).ready(function () {
load_time();
});
function load_time(){
var beforeLoad = (new Date()).getTime();
$('.frame_container iframe').on('load', function() {
var afterLoad = (new Date()).getTime();
var result = (afterLoad - beforeLoad) / 1000;
// beforeLoad = afterLoad;
$(this).parent().find('div.loadingtime').html(result);
});
}
My problem - the beforeLoad value is the same for all iframes. This value should be different for each frame because all fames dont start loading at the exact same time. Any suggestions?