Solved

ASP and Javascript session popup warning problem

Posted on 2007-03-17
7
693 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
  • 3
  • 3
7 Comments
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
Use this;

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

Author Comment

by:Nitestarz
Comment Utility
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
Comment Utility
Try putting the window.close event in the body tag of the popup;

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

Or something like that...  
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Nitestarz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now