[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


ASP and Javascript session popup warning problem

Posted on 2007-03-17
Medium Priority
Last Modified: 2012-06-27
Using ASP and Javascript to do the following.

A user logs into a site and a session is created, 20min by default. I have javascript on every page that sets a timer to load a function that pops up a confirm window 5 min before the session times out. On every page as well, I have asp writing the header to refresh by taking the session.timeout and adding a minute after to it, then refreshing the page, which will have the users page directed to the login page telling them their session has expired.

The problem I have is with the popup window, after it pops up and if the user does not click ok or cancel, the window is still there, and then when the page tries to refresh it crawls along for well over a few minutes, eventually refreshing the page and redirecting the browser to the main login page. If someone clicks ok/cancel during that time it immediately re-directs which is fine. I need a way to have the popup window close itself after the 5 min and let the refresh take place.

Here is the code for the window and how it's called. (the timeout is only set to 2seconds cause I don't like waiting for 5 min )

// Set the timeout for the page, then load the warning before timeout
var t
t=setTimeout( 'ShowTimeoutWarning();', 2000 );

function ShowTimeoutWarning ()
//declare variable agree
var agree
agree=window.confirm('You will be automatically logged out in five minutes unless you do something!\n If you click cancel your session will expire and you will be logged out!');
   if (agree)
      // user is at terminal, reload the window to keep the session alive
      return false;
      //close window and allow asp refresh to boot user to login page

Question by:Nitestarz
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
  • 3
LVL 18

Expert Comment

ID: 18740191
Use this;

setTimeout('window.close()', 10000); // closes window after 10 seconds

Author Comment

ID: 18740435
I wish it was that easy :)

The function get's called after the first timer goes off. Then the window.confirm pops up. If the user does not click ok or cancel after a specified interval, I want the popup to close itself, then the refresh will take over. I've put the setTimeout inside the function and all it does is throw up the confirm box then if you click cancel or ok, then the timer triggers the next event, but it will not close the first popup.
LVL 18

Expert Comment

ID: 18740545
Try putting the window.close event in the body tag of the popup;

<body onload(setTimeout('window.close()', 10000));>

Or something like that...  
Industry Leaders: 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!


Author Comment

ID: 18740701
Didden't think of that, unfortunately it does the same thing, the first window must be ok'd or canceled before the next timer can begin. Im wondering if there is a way to set a countdown timer for the window, if something = 0 then window.close, only thing is I don't know how to go about writing it. It would seem that the settimer would take care of that, since the function is called, a new settimer is loaded and then should close the window. Im thinking it's cause of the type of popup window it is, a javascript popup???
LVL 15

Accepted Solution

stanscott2 earned 500 total points
ID: 18740708
As you've seen, window.confirm doesn't provide a very good solution here, because when the popup is activated, all Javascript timers stop.  Instead, you need to create a custom window with buttons, which CAN be controlled programatically.

There are a lot of free Javascript controls out there you can use -- there's a nice turnkey control available at the Dynamic Drive site here:  http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

It should be able to meet your needs.

Author Comment

ID: 18740921
Stanscott, what I was thinking was that javascript did stop the timers, and it looks like that's the case. Whipped up a quick popup window that loads another page and set's the timeout on that page along with buttons. The link you provided was something I was trying to do but couldn't find any good resources on that "style" of window. Thanks everyone!
LVL 18

Expert Comment

ID: 18741127
I don't see in that link provided where it does a window.close()...

BTW, the close() event I specified is to be placed in the opened popup window.  It is possible that the function will not run due to the window being opened as a child by the parent, not sure but it's possible.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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)
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…

656 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