504网关超时自动刷新页面


504 gateway timeout auto refresh page

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

我认为你可以使用js。我们可以设置一个特定的时间间隔,之后页面将被刷新。我将提供一个示例:

<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>

我在这里发现了一个很好的互动想法。

简而言之,它做了以下事情:

我们定义了两个函数:startTimer()用于body onload事件,它每1000毫秒启动一个timeUp()。它增加全局变量计时器,并检查它是否等于预定义的超时(180)。是=>重新加载页面。如果没有,它会把这个差异放到"timer"div中——这样,页面看起来就像反向计时器。

<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>