Solved

Session Expiration alert

Posted on 2007-12-01
5
1,457 Views
Last Modified: 2012-08-13
Im having issues with the following code.
My requirements are to show an alert when a session is about to timeout.
The current logic is supposed to reload the page when the session alert shows up.
Users might be in the middle of filling out a form and if the page reloads then all there information will be lost.
So I am hoping to find a way to show the alert and whenever a person wants to stay on, just restart the session counter w/o reloading the page.
Thanks very much in advance.

<link rel="stylesheet" type="text/css" href="/js/subModal15/subModal.css" />
<script type="text/javascript" src="/js/subModal15/common.js"></script>
<script type="text/javascript" src="/js/subModal15/subModal.js"></script>
 
<script type="text/javascript">
function alertUser() {
  showPopWin('/js/subModal15/modalContent.html', 400, 250, reloadPage);
}
function reloadPage() {
 location.reload(1); // reload the page
}
window.setTimeout('alertUser()', 3300);
</script>

Open in new window

0
Comment
Question by:parikaa
  • 3
5 Comments
 
LVL 12

Expert Comment

by:Sinoj Sebastian
ID: 20388417
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20388525
You don't have to reload the page to keep the session alive. You only have to request something from the server. You could for example reload one of the images on the page every ten minutes:

window.setInterval("document.getElementById('SomeImage').src='image.jpg?'+(new Date()).GetTime();", 600000);

<img id="SomeImage" src="image.jpg">

The timestamp added to the image url makes sure that the image is not loaded from the cache.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20388563
If you actually want an annoying alert also (and not just silently keep the session alive), just add a conformation box in the code:

window.setInterval("if (confirm('Nagging message here...')) document.getElementById('SomeImage').src='image.jpg?'+(new Date()).GetTime();", 600000);

Or, alternatively, you could just stick with your original code and just don't reload the page. I suppose that the showPopWin function opens a popup window, which means that you already refreshed the session when you asked the user if the session should be refreshed... You should just put a message like "your session has been kept alive regardless if you want it or not" in the popup...
0
 
LVL 5

Author Comment

by:parikaa
ID: 20388765
GreenGhost:

Thanks for your help...i'll give it a try on the large form to reload an image to keep the session alive silently.

However the code that I have does not open a pop up, it is a modal dialog within the same page.
This modal dialog shows up only once!  If I close the dialog, I expect the counter to reset and open again within the given interval time.

Any ideas?
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20388884
> However the code that I have does not open a pop up, it is a modal dialog within the same page.

It doesn't matter how or where the page is opened, as long as it's requested from the server.

> I expect the counter to reset and open again within the given interval time.

Call window.setInterval again when the dialog closes.

Alternatively, you could use window.setInterval instead, but then you might want to use a variable as flag while the dialog is open, so that it doesn't open a lot of dialogs if the page is left open.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now