title: Javascript getting loading time of each iframe source
body: <p>I got a code that reads urls from a text file and puts them in a iframe one after another. I want to calculate the loading time of each page. I do that by marking the time before the iframe starts to load the url, and mark the time right aftrer its loaded. After load minus Before load gives me the loading time of each page.</p>
  
  <pre><code>    $.get("text.txt", function (data) {
          var array = data.split(/\r\n|\r|\n/) 
          var beforeLoad = (new Date()).getTime();    
          var loadTimes = [];
      $('#1').on('load', function () {
          loadTimes.push((new Date()).getTime());           
          $('#1').attr('src', array.pop()); 
              $.each(loadTimes, function (index, value) {             
                  var result = (value - beforeLoad) / 1000;       
                  $("#loadingtime" + index).html(result);
              }); 
      }).attr('src', array.pop());
  });
  </code></pre>
  
  <p>Problem here - before load time. I cant figure out how to mark the time before EACH url starts loading. In the code above beforeload value is a time value before ALL sources are loaded, where i want it to be changing every time a new source gets put into iframe. Any suggestions how i do this?</p>
  
  <p>Edit: fixed it!</p>
  
  <pre><code>   $.get("imones.txt", function (data) {
          var array = data.split(/\r\n|\r|\n/) 
          var beforeLoad = (new Date()).getTime();    
          var loadTimes = [];
              var beforeTimes = [];               
          $('#frame_id').on('load', function () {                                 
              beforeTimes.push(beforeLoad);
              loadTimes.push((new Date()).getTime()); 
              $('#frame_id').attr('src', array.pop());
                  $.each(loadTimes, function (index, value) { 
                      var result = (value - beforeTimes[index]) / 1000;
                          if (result &lt; 0) {
                              result = result * (-1);
                          }   
                      $("#loadingtime" + index).html(result);
                      beforeLoad = value;
                  });
          }).attr('src', array.pop());
      });
  </code></pre>
  
  <p>Not sure what i did there, but this works for me, gonna analyze it now. I made an array of that stores correct before load times of each page.</p>