<html> <head></head> <body> <iframe id="frm" src="about:blank" style="visibility:hidden; width:1px; height:1px;" onload="showsudu()"></iframe> <p>输入一个网站地址:</p> <input id="txt_url" type="text" style="width:300px;" /><input type="button" value="测速" onclick="cesu()" /> </body> <script type="text/javascript"> var show = false; var time = null; function cesu() { var url = document.getElementById("txt_url").value; if(!url)return; document.getElementById("frm").src = url; show = true; var d = new Date(); time = d.getSeconds()*1000+d.getMilliseconds(); } function showsudu() { if(!show)return; var d = new Date(); time = d.getSeconds()*1000+d.getMilliseconds() - time; alert(time+"毫秒"); } </script> </html>
其实你上FireFox的Addon站点看看,这方面的东东不少。
<html>
<head></head>
<body>
<iframe id="frm" src="about:blank" style="visibility:hidden; width:1px; height:1px;" onload="showsudu()"></iframe>
<p>输入一个网站地址:</p>
<input id="txt_url" type="text" style="width:300px;" /><input type="button" value="测速" onclick="cesu()" />
</body>
<script type="text/javascript">
var show = false;
var time = null;
function cesu()
{
var url = document.getElementById("txt_url").value;
if(!url)return;
document.getElementById("frm").src = url;
show = true;
var d = new Date();
time = d.getSeconds()*1000+d.getMilliseconds();
}
function showsudu()
{
if(!show)return;
var d = new Date();
time = d.getSeconds()*1000+d.getMilliseconds() - time;
alert(time+"毫秒");
}
</script>
</html>