如何在PHP上setInterval?

时间:2015-05-10 07:31:34

标签: javascript php

echo '
    <script type="text/javascript">
        setInterval( myfunction , 1000);
        myfunction(){
            window.location = "../index.php";
        }
    </script>';

如果我只是在没有window.location = "../index.php"的情况下致电setInterval它确实有效我看过很多代码,但没有人可以帮助我谢谢你。

2 个答案:

答案 0 :(得分:1)

如果您想在一定时间后重定向或重新加载网页,则只能从客户端触发事件。您可以使用java脚本和html元标记来实现此目的。

1:使用HTML

<meta http-equiv="refresh" content="0";url=http://www.domain.com/new-page.html">

您可以将内容的值设置为时间

2:使用Javascript

<script type="text/javascript">

setInterval(function(){
window.location = "../index.php";
} , 1000);


</script>

答案 1 :(得分:0)

1秒后重定向页面。它运行一次

<script type="text/javascript">

setTimeout(function(){ 
window.location = "../index.php";
}, 1000);

</script>

如果你用php编写,请使用它

<?php
//code here
?>
<script type="text/javascript">

setTimeout(function(){ 
window.location = "../index.php";
}, 1000);

</script>
<?php
//code here
?>

或使用setInterval而不是setTimeout