2016-10-16 130 views
0

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

header()php函數不需要JavaScript。只需使用'window.location.href =「TV_moem_ruki.php」;'在setTimeout函數中 –

+0

謝謝。這一個工作。 – user72160

回答

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是第一頁,你需要返回的頁面。