Solved

Session Expiration alert

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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 …
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…

729 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