Calculating loading time of multiple iframes with javascript
<p>First i create an iframe for each url i have:</p>

<pre><code>$url = array();
$url[] = 'example1.com';
$url[] = 'example2.com';

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

<p>Then i have this javascript that should calculate the time before each frame starts loading, and the time after its loaded: </p>

<pre><code>$(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);
});
}
</code></pre>

<p>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?</p>
