Home > Web Front-end > JS Tutorial > body text

js prevents refresh countdown

php中世界最好的语言
Release: 2018-04-18 13:52:38
Original
1675 people have browsed it

This time I will bring you js to prevent the refresh countdown, what are the precautions for js to prevent the refresh countdown, the following is a practical case, let's take a look.

If it were written in cs code, we might quickly write out how to prevent refreshing, but we have to do front-end development, and the exam is conducted on the page, so the js we learned will be used here.

<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312" />
<title>前端开发</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
var maxtime;
if(window.name==&#39;&#39;){
maxtime = 1*60;
}else{
maxtime = window.name;
}
function CountDown(){
if(maxtime>=0){
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
msg = "距离考试结束还有"+minutes+"分"+seconds+"秒";
document.all["timer"].innerHTML = msg;
if(maxtime == 5*60) alert('注意,还有5分钟!');
--maxtime;
window.name = maxtime;
}
else{
clearInterval(timer);
alert("考试时间到,结束!");
}
}
timer = setInterval("CountDown()",1000);
//-->
</SCRIPT>
<p id="timer"style="color:red"></p>
 
</body>
</html>
Copy after login
In fact, the main idea here is that we put the time in a

variable, and after refreshing, we can then read the data from the variable. We can also use cookie to save the start time and read the cookie first after refreshing. There may be more than just this method. I hope everyone has a better way to communicate.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:



The above is the detailed content of js prevents refresh countdown. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!