Solved

ASP and Javascript session popup warning problem

Posted on 2007-03-17
7
699 Views
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
      window.location.reload();
      }
      else
      return false;
      //close window and allow asp refresh to boot user to login page
}

</script>
0
Comment
Question by:Nitestarz
[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
  • 3
7 Comments
 
LVL 18

Expert Comment

by:mgfranz
ID: 18740191
Use this;

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

Author Comment

by:Nitestarz
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.
0
 
LVL 18

Expert Comment

by:mgfranz
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...  
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:Nitestarz
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???
0
 
LVL 15

Accepted Solution

by:
stanscott2 earned 125 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.
0
 

Author Comment

by:Nitestarz
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!
0
 
LVL 18

Expert Comment

by:mgfranz
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.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
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…

733 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