Topic: Enable users to force log out 15 minutes after logging in.
Idea:
Use JS to write a method to compare the current time with the login time. When the difference between the two time and minute values is greater than 15, use location.href to jump to the exiting ASP page.
Question: How to implement repeated execution of this JS method to achieve time comparison?
Solution: Use JS's setTimeout function to solve this problem.
program code
<script language="JavaScript">
<!--
login_time=15; //Set the length of time allowed to log in, in minutes.
sm=<%=minute(session("in_time"))%>;//The minute when logging in, session("in_time") is the login time.
sh=<%=hour(session("in_time"))%>;//The clock when logging in, session("in_time") is the login time.
CheckTime();
function CheckTime(){//Check the current time
nowtime= new Date();
nh=nowtime.getHours()
nm=nowtime.getMinutes()
if (nh > sh) nm +=60//Compare the current clock with the clock at login
//Login time exceeds login_time, exit
if ((snm - sm) > login_time){
alert("You have been logged in for more than 15 minutes, the system will force you to log out!");
location.href("login_out.asp");
//parent.window.close();
}
delete nowtime;
setTimeout("CheckTime()","10000");//Realize the continuous execution of the CheckTime() method. 10000 is milliseconds, 1s=1000 milliseconds
}
-->
</script>