首页 > 解决方案 > 倒计时完成后如何移动窗口?

问题描述

您好,我用 php 和 javascript 创建了一个倒计时。我有三个文件 test.php、mentenanta.php 和 response.php,它工作正常,但是当倒计时结束时,我想自动回到 index.php。这是我的文件:

测试.php

<?php
    $_SESSION["duration"] = $mentenanta[0]['finish_time'];
    $_SESSION["start_time"] = date("Y-m-d H:i:s");

    $end_time = date('Y-m-d H:i:s', strtotime('+'.$_SESSION["duration"].'minutes', strtotime($_SESSION["start_time"])));
    $_SESSION["end_time"] = $end_time;
?>
<script type="text/javascript">
window.location="mentenanta.php";
</script>

这是mentenanta.php

<?php session_start(); ?>

<div id="response"></div>

<script type="text/javascript"> 
setInterval(function()
{
  var xmlhttp=new XMLHttpRequest();
  xmlhttp.open("GET","response.php",false);
  xmlhttp.send(null);
  document.getElementById("response").innerHTML=xmlhttp.responseText;
},1000)

</script>

这是response.php

<?php 
session_start();

$from_time1 = date('Y-m-d H:i:s');
$to_time1 = $_SESSION["end_time"];

$timefirst=strtotime($from_time1);
$timesecond=strtotime($to_time1);

$differenceinseconds=$timesecond-$timefirst;

if($timesecond > $timefirst){
    echo gmdate("H:i:s", $differenceinseconds); 
}
?>

它工作正常,但我不知道如何设置为在计时器完成时自动将标题移动到 index.php 或其他文件,当然还要设置 XmlHttpsRequest.abort() 来停止它。

标签: javascriptphp

解决方案


推荐阅读