Solved

ASP and Javascript session popup warning problem

Posted on 2007-03-17
7
697 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
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
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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Diminish Pop-up  in 3 seconds 7 49
Asp in server side with Mssql Server 7 4 27
Start Auto-download of File when page loads? 1 21
Autocomplete with Jquery Question 2 20
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

860 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