Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-19
8
Medium Priority
?
656 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
[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
8 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20317817
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
ID: 20318315
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
ID: 20318320
Alternative is submodal

http://www.google.com/search?q=submodal
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:gops1
ID: 20318737
Sorry Michel, i will fix that when I use it next time
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20319504
great, thanks
Michel
0
 
LVL 5

Author Comment

by:parikaa
ID: 20347682
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 2000 total points
ID: 20348801
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
ID: 21812224
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
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…
Suggested Courses

618 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