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==''){ 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>
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!