2017-07-03 24 views

回答

0

您可以通过jQuery的 像

window.setTimeout(function() {location.href="URL of test.php"}, 5000); 
+2

注意做到这一点官方支持的方式,这不是jQuery的,但纯香草JS – DarkBee

+1

这样即使刷新后5秒钟也会刷新。 OP明确指出:“我试图刷新一次页面” –

+1

好吧,然后在刷新页面一次后设置会话变量,检查相同的变量,如果变量不存在,则运行代码,否则不运行代码。 – GYaN

0
在PHP

做到这一点,您可以:

if(is_page('test.php') && !isset($_GET['r'])){ 
    header("Refresh: 5;url='http://zasite.com/test.php?r=1'"); 
} 

注意:这只能如果完成标题还没有被发送http://php.net/manual/ro/function.headers-sent.php否则你会以aw结束arning和刷新将不起作用。一种解决方法是:

if(is_page('test.php') && !isset($_GET['r'])){ 
    if(!headers_sent()){ 
     header("Refresh: 5;url='http://zasite.com/test.php?r=1'"); 
    } else { 
     echo '<meta http-equiv="refresh" content="5" ; url=http://zasite.com/test.php?r=1>'; 
    } 
} 

OR - PHP与Gyandeep Sharma的JS回答

if(is_page('test.php') && !isset($_GET['r'])){ 
    if(!headers_sent()){ 
     header("Refresh: 5;url='http://zasite.com/test.php?r=1'"); 
    } else { 
     echo '<script>window.setTimeout(function() {location.href="http://zasite.com/test.php?r=1";}, 5000);</script>'; 
    } 
}