获得此脚本将网址加载到iframe中:
<script type="text/javascript">
var imones = [];
imones.push('example.com');
imones.push('example1.com');
imones.push('example2.com');
$.each(imones, function (index, value) {
var gg="http://anyorigin.com/get?url="+imones[index]+"&callback=?";
console.log("nuorados- "+gg);
$.getJSON(gg, function(data) {
var iframe = $("#output")[0];
var doc = iframe.document;
if (iframe.contentDocument) {
doc = iframe.contentDocument;
} else if (iframe.contentWindow) {
doc = iframe.contentWindow.document;
}
doc.open();
// gets times before loading each frame
var beforeTime = [];
var beforeloadingtime = (new Date()).getTime();
beforeTime.push(beforeloadingtime);
console.log("before time- "+beforeTime);
doc.writeln(data.contents);
doc.close();
//gets times after loading each frame
var loadTime = [];
var loadingtime = (new Date()).getTime();
loadTime.push(loadingtime);
console.log("loading time- "+loadTime);
});
});
</script>
<iframe id=output ></iframe>
我正在尝试为每个帧获取时间值/在加载帧之前和/之后/加载帧。目前我在运行上述脚本的控制台中获得这些结果:
before time - 1362127940145
loading time- 1362127940160
before time - 1362127940528
loading time- 1362127940535
before time - 1362127940573
loading time- 1362127940584
(loading time) - (before time) = total loading time of each frame.
我得到的数字没有意义,因为它们都很短,所以我不认为我在这里得到正确的加载时间。有关如何改进此脚本的任何建议吗?
编辑:加载时间可能是正确的,但我认为之前需要将其放在其他地方......