Solved

Session Expiration alert

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

738 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