在特定时间重定向页面

时间:2016-10-16 10:16:51

标签: php html time url-redirection

html / php页面需要重定向到另一个html / php页面,该页面应保持打开一段时间。然后,它需要恢复原状。

<meta http-equiv="refresh" content="1;URL='TV_moem_ruki.php'" />

在页面加载后立即重定向。

我已尝试合并此

header( "Location: TV_moem_ruki.php") ; 

进入下面的脚本,该脚本会在某个时间点刷新页面,但它不起作用。

<script>
refreshAt(13,10,0); //Will refresh the page at 11:05am
</script>
<script>
function refreshAt(hours, minutes, seconds) {
    var now = new Date();
    var then = new Date();

    if(now.getHours() > hours ||
       (now.getHours() == hours && now.getMinutes() > minutes) ||
        now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
        then.setDate(now.getDate() + 1);
    }
    then.setHours(hours);
    then.setMinutes(minutes);
    then.setSeconds(seconds);

    var timeout = (then.getTime() - now.getTime());
    setTimeout(function() { window.location.reload(true); }, timeout);
header( "Location: TV_moem_ruki.php") ; 
}
</script>

1 个答案:

答案 0 :(得分:0)

您可以通过在第二页(仅保持打开几秒钟)的代码中粘贴此代码,以多种方式执行此操作:

<meta http-equiv="refresh" content="{numberOfSeconds}; url='TV_moem_ruki.php'" />

或使用javascript

window.setTimeout(function () {
    window.location.href = 'TV_moem_ruki.php'
}, numberOfSeconds * 1000)

这假设TV_moem_ruki.php是第一页,您需要返回的页面。

相关问题