Solved

Session Expiration alert

Posted on 2007-12-01
5
1,453 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 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

14 Experts available now in Live!

Get 1:1 Help Now