显示IFRAME的加载时间 [英] Displaying load time of IFRAME

查看:88
本文介绍了显示IFRAME的加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我试图计算完全下载并呈现IFRAME内容并将其显示在DIV元素中所花费的时间.然后使用按钮刷新IFRAME的内容,然后重新计算时间并将其显示在同一DIV元素中.

我设法刷新了IFRAME的内容,但是显示了窗口而不是IFRAME的加载时间.

代码在下面列出

Hi im trying to calculates the time taken to completely download and render the contents of the IFRAME and display it in a DIV element. And refresh the contents of the IFRAME with a button and recalculate the time and display it in the same DIV element.

I have managed to refresh the contents of the IFRAME and but display the load time of the window not the IFRAME.

code is listed below

<html>
<head>

<script type="text/javascript">

//calculate the time before calling the function in window.onload
beforeload = (new Date()).getTime();
function pageloadingtime()
{

     //calculate the current time in afterload

    afterload = (new Date()).getTime();


     // now use the beforeload and afterload to calculate the seconds
    secondes = (afterload-beforeload)/1000;


    document.getElementById("loadingtime").innerHTML = "<font color='red'>(You Page Load took " + secondes + " seconde(s).)</font>";

}

window.onload = pageloadingtime;



</script>

<script type="text/javascript">

function Reload() {
var f = document.getElementById('iframe1');
f.src = f.src;
}

</script>

<title>load time</title>
</head>


<body>

<div id="loadingtime"></div>

<br>

<iframe id="iframe1" width="800" height="350" src="http://google.com"></iframe>
<br>

<input type="button" value="Reload" onClick="pageloadingtime()" onClick="Reload();">

<br>


</body>
</html>

推荐答案

您遇到的问题是您使用的是window.onload,而不是iframe的onload属性.输入按钮触发了Reload()和pageloadingtime(),这也是一个很大的问题.我通过将beforeload的设置也移到Reload()并将触发器附加到iframe的onload属性来修复代码:

The problem you are having is that you are using window.onload and not the iframe''s onload attribute. The input button triggered both Reload() and pageloadingtime() which is also a big no no. I fixed your code by moving the setting of beforeload also into Reload() and attaching the trigger to iframe''s onload attribute:

<html>
<head>

<script type="text/javascript">

//calculate the time before calling the function in window.onload
beforeload = (new Date()).getTime();
function pageloadingtime()
{

     //calculate the current time in afterload

    afterload = (new Date()).getTime();


     // now use the beforeload and afterload to calculate the seconds
    secondes = (afterload-beforeload)/1000;


    document.getElementById("loadingtime").innerHTML = "<font color='red'>(You Page Load took " + secondes + " seconde(s).)</font>";

}

//window.onload = pageloadingtime;



</script>

<script type="text/javascript">

function Reload() {
    beforeload = (new Date()).getTime();
    var f = document.getElementById('iframe1');
    f.src = f.src;
}

</script>

<title>load time</title>
</head>


<body>

<div id="loadingtime"></div>

<br>

<iframe id="iframe1" width="800" height="350" src="http://google.com" onload="pageloadingtime();"></iframe>
<br>

<input type="button" value="Reload" onClick="Reload();">

<br>


</body>
</html>



玩得开心!

-MRB



Have fun!

-MRB


非常感谢……我只是在如何将reload函数链接到iframe上遇到了麻烦,因此Reload()和pageloadingtime()被触发单击按钮...但是我会记住onload命令.再次感谢!
Hi thank you so much ... i was just having trouble with how to put link the reload function to the iframe hence the Reload() and pageloadingtime() being triggered by a button click ... but i shall keep the onload command in mind. thanks once again!


这篇关于显示IFRAME的加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆