Home > Web Front-end > JS Tutorial > js implements anti-refresh countdown code display

js implements anti-refresh countdown code display

巴扎黑
Release: 2017-09-07 11:41:12
Original
1222 people have browsed it

This article mainly introduces the js anti-refresh countdown code and the js countdown implementation code in detail, which has a certain reference value. Interested friends can refer to it

Recent maintenance exam System, I accidentally clicked the refresh button during the exam test, but the countdown above was not affected. There are also such examples in several blogs, so I want to see how it prevents refresh.

If it is written in cs code, we may quickly write out how to prevent refreshing, but we need to carry out front-end development, and the exam is conducted on the page, and the js we have 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(&#39;注意,还有5分钟!&#39;);

--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 cookies to store 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.

The above is the detailed content of js implements anti-refresh countdown code display. 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