Refresh HTML Page in Browser Automatically on Time

2019-01-23 15:24发布

问题:

Is it possible to automatically refresh a website on a timer, like every 15 minutes? Basically, we will be making updates to a website and we want it to automatically refresh so it will show up on a big monitor we have which is controlled from a different computer.

So instead of going to that other computer to click refresh when changes are made, it would just automatically refresh so we can keep it up there.

Thanks!

回答1:

Place this inside <head> to refresh page after 900 seconds:

<meta http-equiv="refresh" content="900"> <!-- Refresh every 15 minutes -->

For what it's worth, the w3c has officially deprecated this feature, but browsers continue to support this feature. For your purposes, this is an ideal solution. It's just not a recommended solution for "public" (www)-facing web sites any more.



回答2:

You dont even need js to do this! Look at the refresh meta tag: http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm You can use this to refresh the page on any interval.



回答3:

Although the refresh meta tag is the simpler solution to update information on a webpage it is also a pretty old and dated solution.

Imagine for example that Google maps would need to refresh the whole page when you pan the map view. There is where ajax comes in, you can find a lot information about it online like this for example.

I don't know specifically what was your intention but just wanted to give this background information, if just a refresh is really what you need then the answers from box86rowh and ckittel is all you need.



回答4:

window.setTimeout(function(){
//refresh the page after 900,000 miliseconds (15 minutes)


//reload the page (javascript has many ways of doing this)
location.reload();
},900000);

That should help.



回答5:

Pass the url in the querystring, and then just load it in a frame

source: javascriptkit.com

<script>
<!--
should range from 0 to 59
var limit="0:30"
if (document.images){
    var parselimit = limit.split(":")
    parselimit = parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
    if (!document.images)
        return
    if (parselimit == 1)
        window.location.reload()
    else{ 
        parselimit -= 1
        curmin = Math.floor(parselimit/60)
        cursec = parselimit%60
        if (curmin!=0)
            curtime = curmin+" minutes and "+cursec+" seconds left until page refresh!"
        else
            curtime = cursec+" seconds left until page refresh!"
        window.status = curtime
        setTimeout("beginrefresh()",200)
    }
}

 window.onload = beginrefresh
 //-->
</script>
</head>
<body>
<iframe src="" id="refreshResults" frameborder="0" width="1800" height="1800"></iframe>

<script>

    var http = new XMLHttpRequest();

    $(function(){
        $("#refreshResults").attr('src','<%=Request.Querystring("w")%>');
    });

</script>


回答6:

This will be of help. I guess you can try it out

<meta http-equiv="refresh" content="1">