Solved

Looking for code for a modal window that alerts users before session timeout

Posted on 2007-11-19
8
646 Views
Last Modified: 2012-05-05
Does anyone have sample code for a modal window that will alert user of session timeout a few minutes before a two hour long session is ending?

Thanks very much in advance.
0
Comment
Question by:parikaa
8 Comments
 
LVL 17

Expert Comment

by:gops1
Comment Utility
window.open though it is browser compatible but it is difficult to achieve a modal popup from it. This code might give you some ideas.

May be you can try with some DHTML popup and disable all clicks from parent.
<html>

	<head>

		<title>Script Demo Gops&reg;</title>

		<style>

			body, table,input, select,span{font-family:verdana;font-size:xx-small;}

		</style>

		<script language="javascript">

			var timer=null;

			var sessionTime=15000; //assuming 15 seconds

			function new_popup(title, name) {

				newWindow=window.open ("", 'popup',

				'screenx=60,\

				screeny=60, \

				toolbar=,   \

				directories=,\

				status=,     \

				scrollbars=1,\

				resizable=1, \

				menubar=,    \

				height=400,  \

				width=400'

				);

				newWindow.document.open();

				newWindow.document.write('<html><head><title>' + title + '</title></head>');

				newWindow.document.write('<body onBlur="this.focus()"  bgcolor="#ffffff" leftmargin=0 marginwidth=0 topmargin=0 marginheight=0>');

				newWindow.document.write(' <a href="javascript:window.opener.location.href=\'sessiontimeout.html\';self.close();">Close</a>');

				newWindow.document.write('</body></html>');

				newWindow.document.close();

				return true;

			}

 

			window.onload=function(){

				if (document.addEventListener){

					document.addEventListener("mouseover", resetSession, true);

					document.addEventListener("click", resetSession, true);

					document.addEventListener("keypress", resetSession, true);

				}else if(document.attachEvent){

					document.attachEvent("onmouseover", resetSession);

					document.attachEvent("onclick", resetSession);

					document.attachEvent("onkeypress", resetSession);

				}

				document.getElementById('stimer').value=sessionTime;

				timer=setInterval("runSessionTimer()",1000);

			}

 

			function resetSession(){

				sessionTime=15000;

				clearInterval(timer);

				document.getElementById('stimer').value=sessionTime;

				timer=setInterval("runSessionTimer()",1000);

			}

 

			function runSessionTimer(){

				sessionTime=sessionTime-1000;

				document.getElementById('stimer').value=sessionTime;

				if(sessionTime<=0){

					new_popup("Session Time Out","Session");

					clearInterval(timer);

				}

			}

 

		</script>

	</head>

	<body>

		Session Timer:<input type="text" value="" id="stimer">

	</body>

</html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Gops, please fix your code to include values on
toolbar=,   \
directories=,\
status=,     \

or remove them. I have seen this code before and it is not valid without a value or without the =
so either

toolbar=1,   \
directories=1,\
status=1,     \

or

toolbar,   \
directories,\
status,     \


OR

toolbar=0,   \
directories=0,\
status=0,     \

OR remove them since specifying one parameter turns the rest off
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Alternative is submodal

http://www.google.com/search?q=submodal
0
 
LVL 17

Expert Comment

by:gops1
Comment Utility
Sorry Michel, i will fix that when I use it next time
0
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!

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
great, thanks
Michel
0
 
LVL 5

Author Comment

by:parikaa
Comment Utility
mplungjan,

Thanks the submodal is exactly what I am looking for!
Can you please help me to display the submodal window when a session is about to expire; instead of when a button is clicked?
Thank you very much
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
You mean


<html>

<head>

<link rel="stylesheet" type="text/css" href="subModal.css" />

<script type="text/javascript" src="common.js"></script>

<script type="text/javascript" src="subModal.js"></script>

<script>

var tID = "";

function sessionEnd() {

  showPopWin('yoursessionIsEnding.html', 300, 400, reloadPage);

}

function reloadPage() {

  location.reload(1); // reload the page

}

</script>

</head>

 

<body onLoad="tID=setTimeout('sessionEnd()',<%= Session.Timeout %>*60000)">

Open in new window

0
 

Expert Comment

by:bisola_4
Comment Utility
I am truly happy i saw this..
I just downloaded the submodal files
except i want the window to be called only once per session in the browser.

I called it on the website's homepage but each time a user goes to the homepage, it displays the DHTML modal window once more.. kind'a annoying.

So I will post a question on how to modify it to show just once per session (only come back after the browser is re-opened)

Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

728 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

8 Experts available now in Live!

Get 1:1 Help Now