0
私はセッションストレージに格納されたカウントダウンタイマーのために、このコードを持って、それがうまく働いていますが、カウントダウンタイマーが明らかfinshedされる前に、私は、ユーザーがサイトを離れた場合カウントダウンタイマー終了後にクリア(ローカルストレージ、セッションストレージ)?
- のような多くの機能を追加する必要が
ローカルセッション - カウントダウンタイマーが
インデックスページをfinshedされる明確なローカルセッション: -
<!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);
私が提出し、ページを送信し、インデックスページに戻るために戻るボタンを使用した場合、カウントダウンタイマーは、ページが送信された場所から続けるどのように私はそれがfinshedされていない場合でも送信ヒットをクリアすることができます – mohammed
'clearCountdown (); 'あなたの提出でも – Bikas