请问如何用javascript写一个方法,从打开这个URL到完成(如状态栏下的‘完毕’)所用的时间。

解决方案 »

  1.   

    onload事件应该就可以满足你的要求了
      

  2.   

    <script language="javascript">
    var seconds=0;
    function calculate(){
    if(document.readyState!='complete'){seconds++;setTimeout('calculate',1000);}
    }
    </script>
    <body onLoad="calculate()">
    <script language="javascript">
    document.write("加载时间为"+seconds+"秒");
    </script>
    </body>
    这样行不行?
      

  3.   


    <HTML>
      <head>
      <script type="text/javascript">
        var startTime
        var win
        function linkTo(url)
        {   
          startTime = new Date()
          win = window.frames["tar"]
          win.document.location.href = url
          countTime()
        }

        function countTime()
        {
          if (win.document.readyState != "complete")
          {
            setTimeout(countTime, 1)
          }
          else
          {
            alert("页面加载耗时:" + (new Date() - startTime)/1000 + "秒")
          }
        }
      </script>

    </head><BODY>
    <a href='#' onclick='linkTo("test.htm?s=http://community.csdn.net/Expert/TopicView1.asp?id=5287144")'>csdn</a>
    <a href='#' onclick='linkTo("test.htm?s=http://www.163.com")'>163</a><br><br>
    <iframe src="" name="tar"></iframe>
    </BODY>
    </HTML>test.htm
    --------------------
    <HTML>
    <BODY>
    <p id='urlText'></p>
    <iframe id=tt src=""></iframe>
    <script>
      var url = document.location.search.split("?s=")[1]
      window.frames["tt"].document.location.href = url
      urlText.innerText = url
    </script></BODY>
    </HTML>
      

  4.   

    调试了一下,这样就可以了.
    -----------------------
    <script language="javascript">
    var seconds=0;
    function calculate(){
    if(document.readyState!='complete'){seconds++;window.setTimeout('calculate()',10);}
    else document.write('加载时间为'+(seconds/100)+'秒');
    }
    </script>
    <body>
    <script>calculate();</script>
    <img src="http://today.java.net/images/tiles/111-nutch.gif" />
    </body>
      

  5.   

    <body>
    <script language="javascript">
    var seconds=0;
    function calculate(){
    if(document.readyState!='complete'){seconds++;window.setTimeout('calculate()',10);}
    else alert('加载时间为'+(seconds/100)+'秒');
    }
    </script>
    <script>calculate();</script>
    <iframe width=300 height=200 src="http://www.xinhuanet.com/" /><br>
    </body>这个效果明显一点
      

  6.   

    还有用这个效果比较好 = =
    <script language="javascript">
    var seconds=0;
    function calculate(){
    if(document.readyState!='complete'){seconds++;window.setTimeout('calculate()',10);}
    else document.getElementById('show').value='页面完成,加载时间为'+(seconds/100)+'秒';
    }
    </script><body>
    <input name="show" type="text" id="show" value="正在加载,请稍等。" size="30" readOnly >
    <br><script>calculate();</script>
    <iframe width=300 height=200 src="http://www.xinhuanet.com/" /><br></body>