zoukankan      html  css  js  c++  java
  • 让页面在打开时自动刷新

    <script>
        function window.onload() {
            if (location.href.indexOf('#reloaded') == -1) {
                location.href = location.href + "#reloaded"location.reload()
            }
        }
    </script>
    -----------------------------------------------------------------------------
     
    我的网页的图片较多,而服务器也不是很好,所以每次打开网页后总有一、两幅图片无法显示,但刷新一遍后又全部可显示了。 
    不想让浏览网页的人每次都点“刷新”按钮,请问如何在网页中加入一些代码,让网页在打开后又自动刷新一次? 
    --------------------------------------------------------------- 

    把下面代码加在<head></head>之间 
    <meta http-equiv=refresh content=5 > //每隔5秒刷新一次
    --------------------------------------------------------------- 

    三种方法: 
    1.
    <script>
        function refreshPage(the_duration) {
            setTimeout("self.location.reload();", the_duration * 1000);
        }
        self.onload = function() {
            refreshPage(1); //里面的1代表1秒,未刷新的间隔时间,你可以改成你想要的 
        };
    </script>
    2.<body onload='setTimeout("location.reload()",1000)'> 
    3.<meta http-equiv="refresh" content=几秒> 
    只刷新一次: 
    <body onload="location.replace()"> 
    --------------------------------------------------------------- 

    来晚了,楼上兄说的对 
    --------------------------------------------------------------- 


    楼上这样的方法是每隔5秒钟就要刷新一次,对服务器的压力很大,如果在大量的请求连接以及服务器不是很好的情况下很可能变成服务器的当机。 
    所以比较好的办法是在用Javascript来实现。在装载完了以后刷新一下,只要用如下的代码: 
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
    function refresh() 

    history.go(0); 

    setTimeout("refresh()",1000); 
    //--> 
    </SCRIPT> 


    这个是在不管本页面的缓存情况下,向服务器重新请求一次。 
    setTimeOut 是在1秒钟以后刷新本页面。 
    把上面的代码放到<head>  </head>之间,以1000×n计算n秒以后刷新,替换1000; 


    试试看吧。 
    --------------------------------------------------------------- 
  • 相关阅读:
    deb app install under terminal
    修改代理
    virtualenv install &usage
    what a pietty
    晚上想睡觉不要喝可乐
    ubuntu server 调教
    修改代理
    修改网关为静态IP
    infobright install tips
    i like fujishu laptop more than mac
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061164.html
Copyright © 2011-2022 走看看