简体   繁体   中英

504 gateway timeout auto refresh page

是否可以添加一些代码,如果页面超时(由于共享主机过载),我可以在收到错误“ 504网关超时”时刷新页面

I think you can use js for this.We could set in a specific interval of time after which the page is to be refreshed.I will provide an example :

<html>
    <head>
        <script type="text/JavaScript">
        function timeRefresh(timeoutPeriod) 
        {
           setTimeout("location.reload(true);",timeoutPeriod);
        }
        </script>
    </head>

    <body onload="JavaScript:timeRefresh(10000);">

      <p>This page will auto referesh in 10 Sec..... please wait </p>

    </body>
</html>

I found good interactive idea here .

In brief, it does the following:

We define two functions: startTimer() for body onload event, it starts every 1000ms the second one - timeUp(). It increments global var timer and checks if it's equal to pre-defined timeout (180). If yes, reloads the page. If no, it puts the difference to "timer" div - so, the page looks like reverse timer.

<html>
<head>
<script type="text/javascript">
var timer=0;
function startTimer()
{
    setInterval("timerUp()",1000);
}

function timerUp()
{
    timer++;
        var resetat=180; //change this number to adjust the length of time in seconds
    if(timer==resetat)
    {
        window.location.reload();
    }
    var tleft=resetat-timer;
    document.getElementById('timer').innerHTML=tleft;
}

</script>
</head>
<body onload="startTimer()">
Seconds until page reloads:
<div id="timer">
</div>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM