Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java Script/Coldfusion: Timeout Script for user to end session or continue

Posted on 2008-10-11
3
Medium Priority
?
1,179 Views
Last Modified: 2013-12-24
I found this script (see below) browsing through the archives and I hope someone out there will help me refine it to suit my current need. I need to warn users that their session is about to end after 5 minutes of      inactivity ( no mouse click or key stroke)

For testing purposes the Total Session time is 5 minutes.:
- so at  3 minutes, I needs a pop up to say "your session is about to end in 2 minutes" .
- After 5 minutes of inactivity , you get a "session has ended due to 5 minutes of inactivity" and then the user hit sok but is then redirected to a log in page. (similar to the Bank of America logout message for all you  BofA customers familiar with their session log out message)

I would like to link the script in the header.inc I created that is called/loaded whenever you access a page.  I don't want to copy and paste the script in all the pages.

Thanks in advance for any help you can provide...

<script>
var tId="";
window.onload=resetTimer;
window.onmousemove=function(){ resetTimer() }
function resetTimer() {
  clearTimeout(tId)
  document.getElementById('warning').style.display='none';
  tId = setTimeout('warning()',20*60*1000);
}
function warning() {
  document.getElementById('warning').style.display='';
  tId = setTimeout('redirect()',5*60*1000);
}
function redirect() {
  location = 'logout.cfm';
}
</script>

Open in new window

0
Comment
Question by:CF_newbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 22713484
Do you have the element with the id "warning" to have the "popup" element?  You could also use an alert but that will stop the next part from happening if they don't get rid of the alert.
To get the timing you want you modify the code as I have below.  If that is all you need then this should work for you.  Let me know if you have a question or need other help though.
bol

<script>
var tId="";
window.onload=resetTimer;
window.onmousemove=function(){ resetTimer() }
function resetTimer() {
  clearTimeout(tId)
  document.getElementById('warning').style.display='none';
  tId = setTimeout('warning()',3*60*1000);
}
function warning() {
  document.getElementById('warning').style.display='';
  tId = setTimeout('redirect()',2*60*1000);
}
function redirect() {
  window.location = 'logout.cfm';
}
</script>

Open in new window

0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 22738207
I'm glad I could help.  Thanks for the grade, the points and the fun question.
bol
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question