Javascript 倒计时计时器完成后清除(本地存储、会话存储)?

Javascript 倒计时计时器完成后清除(本地存储、会话存储)?,javascript,html,timer,local-storage,Javascript,Html,Timer,Local Storage,我有这个倒计时计时器的代码,它存储在会话存储中,它工作得很好,但我需要添加更多的功能,如 如果用户在倒计时结束前离开站点,则清除 地方会议 当倒计时计时器结束时清除本地会话 索引页:- <!DOCTYPE html> <html lang=""> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <meta name

我有这个倒计时计时器的代码,它存储在会话存储中,它工作得很好,但我需要添加更多的功能,如

  • 如果用户在倒计时结束前离开站点,则清除
    地方会议
  • 当倒计时计时器结束时清除本地会话
索引页:-

<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    <meta name="Author" content=""/>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="myform"></div>
<b><p>this is the index page</p></b>
    <form id="" name="myform" action="submit.html" method="post">

    </form>
<script src="timer.js"></script>
</body>
</html>

无标题文件
这是索引页

提交页面:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
    </head>
    <body>

            <h1>submit is working</h1>



    </body>
</html>

新网络项目
提交有效
timer.js

if(sessionStorage.getItem("total_seconds")){
    var total_seconds = sessionStorage.getItem("total_seconds");
} else {
    var total_seconds = 60*1;
}
var minutes = parseInt(total_seconds/60);
var seconds = parseInt(total_seconds%60);
function countDownTimer(){
    if(seconds < 10){
        seconds= "0"+ seconds ;
    }if(minutes < 10){
        minutes= "0"+ minutes ;
    }

    document.getElementById("myform").innerHTML = "الزمن المتبقى "+seconds+" : "+minutes;
    if(total_seconds <= 0){
        setTimeout("document.myform.submit()",1);

    } else {
        total_seconds = total_seconds -1 ;
        minutes = parseInt(total_seconds/60);
        seconds = parseInt(total_seconds%60);
        sessionStorage.setItem("total_seconds",total_seconds)
        setTimeout("countDownTimer()",1000);
    }
}
setTimeout("countDownTimer()",1000);
if(sessionStorage.getItem(“总秒”)){
var total_seconds=sessionStorage.getItem(“total_seconds”);
}否则{
var total_seconds=60*1;
}
var minutes=parseInt(总秒数/60);
var seconds=parseInt(总秒数%60);
函数倒计时(){
如果(秒<10){
秒=“0”+秒;
}如果(分钟<10){
分钟=“0”+分钟;
}
document.getElementById(“myform”).innerHTML=“秒+”:“+分钟;

如果(总)秒你可以这样做

function clearCountdown() {
    sessionStorage.removeItem("total_seconds")
};

window.onunload = clearCountdown();
并在函数中更新if,如下所示

if(total_seconds <= 0){
        clearCountdown();
        setTimeout("document.myform.submit()",1);

if(total_seconds您可以这样做

function clearCountdown() {
    sessionStorage.removeItem("total_seconds")
};

window.onunload = clearCountdown();
并在函数中更新if,如下所示

if(total_seconds <= 0){
        clearCountdown();
        setTimeout("document.myform.submit()",1);

if(如果我点击提交并移动至提交页面,使用后退按钮返回索引页面,则倒计时计时器将从页面提交的位置继续。如果我点击提交并移动至提交页面,并使用后退按钮返回索引页面,则倒计时计时器将继续f当我点击submit(提交)时,即使页面未被查找,如何清除