<%
Session.Timeout = 5 ' set to 5 minutes for example (we really are going to use 2 minutes 10 seconds)
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Client Side Session Timeout Check</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005-2010 Roderick Divilbiss">
<style type="text/css">
#warningMsg {
position:absolute;
display:none;
width:375px;
color:#000000;
border:3px solid #FF0000;
padding:10px;
background-color:#FFFF00;
top:-400px;
left:-400px; font-weight:bold
}
#btnDiv {
text-align:center;
}
</style>
<script type="text/javascript">
function popMessage() {
var top=0;
var left=0;
var scrollTop = 0;
var top;
document.getElementById('warningMsg').style.display='block';
scrollTop = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : window.pageYOffset;
// if top is set at the clientHeight minus the division height divided by 2 plus the scrollTop it will be in the middle;
top = ((document.documentElement.clientHeight-82)/2)+scrollTop;
// if left = the clientWidth minus the division width divided by two is the division will center.
left = (document.documentElement.clientWidth-375)/2;
document.getElementById('warningMsg').style.top=(top)+'px';
document.getElementById('warningMsg').style.left=(left)+'px';
}
function closePopMessage(answer) {
if (answer==true) {
document.getElementById('warningMsg').style.display='none';
top.location=document.location;
}
}
var timeout=130000; // 2 minutes, 10 seconds...don't need to wait all day for an example
var warning=120000; // 2 minute warning
var dt = new Date();
var start=dt.getTime();
var warned=false;
function checkTime() {
var d=new Date();
var now=d.getTime();
var timeSpent=(now-start);
var secondsLeft=((timeout-timeSpent)/1000);
var minutesLeft=Math.floor(secondsLeft/60);
secondsLeft=Math.floor(secondsLeft-(minutesLeft*60));
var refresh;
if (timeSpent > timeout) {
document.location='sessionExpired.asp';
}
if (timeSpent > (timeout-warning)) {
if (warned==false) {
popMessage();
warned=true;
}
document.getElementById('sessionStatus').innerHTML='You have in '+minutesLeft+' minutes: '+secondsLeft+' seconds remaining.';
} else {
document.getElementById('sessionStatus').innerHTML='You have in '+minutesLeft+' minutes: '+secondsLeft+' seconds remaining.';
}
setTimeout('checkTime()',1000);
}
</script>
</head>
<body onload="checkTime();">
<div><span id="sessionStatus"></span></div>
<div id="warningMsg">Your session will time out in two minutes.<br>
To keep your session active, please click OK.<br>
<div id="btnDiv"><input type="button" name="btnOK" value="OK" onclick="closePopMessage(true);"></div></div>
</body>
</html>
Date Validation Using JavaScript .
Cross-Browser Clipboard Copy .
Loading Images With Remote Scripting .
Why JavaScript In Hyperlinks Is Bad .
Change The Submit Button To Show Waiting For AJAX Response .
European Date Validation Using JavaScript .
Database Results To Client Side Array .
Reading Files With JavaScript .
AJAX For Plain Text And HTML .