?
Solved

Session Expiration alert

Posted on 2007-12-01
5
Medium Priority
?
1,462 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

762 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