By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Session Timeout Popup(before 2 mints session expired one popup will come and will ask

P: 1
i am having problem with my site when user is idle for some time then before 3 mints session getting expired one popup will come and will ask if you want to renew your session then click ok or else cancel.so when i am clicking on ok we are getting response from the server but after that we are not able to click any of the link.
could you please help me out. Thank In Advance.
Expand|Select|Wrap|Line Numbers
  1. var alertDuration;
  2. var sessionTimeoutDuration;
  3. var alertTime;
  4. var isIE8 = window.XDomainRequest ? true : false;
  5. function startTimer(){
  6.     //Configure the parameters to Timeout to change
  7.     //  i.  session timeout duration (currently set to 30 minutes) and
  8.     //  ii. time before session timeout the user should be alerted (set to 3 minutes)
  9.     timer = new Timeout(5,3);
  10.     timer.start();
  11. }
  12.  
  13. function Timeout(std,ad){
  14.     sessionTimeoutDuration = std;
  15.     alertDuration = ad;
  16.     alertTime = ((sessionTimeoutDuration * 60 * 1000) - (alertDuration * 60 * 1000));
  17. }
  18.  
  19. Timeout.prototype.cookieString = "sessionexpiry=";
  20. Timeout.prototype.confirmDisplayed = "confirmDisplayed=";
  21. Timeout.prototype.renewURL = "../../pages/ceppages/renew.iface";
  22. Timeout.prototype.logoutURL = "../../pages/ceppages/logout.jsp";
  23. Timeout.prototype.sessionTimeOutURL = "../../pages/ceppages/logout.jsp";
  24.  
  25. Timeout.prototype.start = function(){
  26.     var currentPage = window.location;
  27.     //do not run if the call happens from the logout page
  28.     if((currentPage.toString()).indexOf(this.logoutURL) != -1){
  29.         return;
  30.     }
  31.     //reset flag
  32.     document.cookie = this.confirmDisplayed + "false";
  33.     var ms = new Date().getTime() + alertTime;
  34.     document.cookie = this.cookieString + encodeURIComponent(ms);
  35.     //create a random integer between 10 & 20
  36.     var interval = (Math.floor(Math.random() * 10)) + 10;
  37.     timer = window.setInterval("Timeout.prototype.check()",interval * 1000);
  38. }
  39.  
  40. Timeout.prototype.stop = function(){
  41.     //Not implemented at this time. 
  42. }
  43. Timeout.prototype.check = function(){
  44.     if(this.isConfirmDisplayed() == "true"){
  45.         return;
  46.     }
  47.     var expTime = this.getExpiryTime();
  48.     var now = new Date().getTime();
  49.     if(now >= expTime){
  50.         document.cookie = this.confirmDisplayed + "true";
  51.         var choice = this.displayConfirm(expTime);
  52.         if(choice){
  53.             alert("extending session!!");
  54.             this.extendSession();
  55.         }else{
  56.             this.logout();
  57.         }
  58.     }
  59. };
  60. Timeout.prototype.isConfirmDisplayed = function(){
  61.     var cookies = document.cookie;
  62.     var position = cookies.indexOf(this.confirmDisplayed);
  63.     if(position != -1){
  64.         var end = cookies.indexOf(";",position);
  65.         if(end == -1){end = cookies.length};
  66.         var conDisp = decodeURIComponent(cookies.substring(position + this.confirmDisplayed.length,end));
  67.         return conDisp;
  68.     }
  69. };
  70.  
  71. Timeout.prototype.getExpiryTime = function(){
  72.     var cookies = document.cookie;
  73.     var position = cookies.indexOf(this.cookieString);
  74.     if(position != -1){
  75.         var end = cookies.indexOf(";",position);
  76.         if(end == -1){end = cookies.length};
  77.         var expTime = decodeURIComponent(cookies.substring(position + this.cookieString.length,end));
  78.         return parseInt(expTime);
  79.     }
  80. };
  81.  
  82. Timeout.prototype.displayConfirm = function(expTime){
  83.     var message = "Your current session will time out in approximately " + alertDuration + " minutes, at ";
  84.     message += this.formatDate(new Date(expTime + (alertDuration * 60 * 1000)));
  85.     message += ".\n\nSelect OK to renew your session and continue using eCEM Tool.  Otherwise select Cancel to logout.";
  86.     return window.confirm(message);
  87. };
  88.  
  89. Timeout.prototype.formatDate = function(expDate){
  90.     var hours = expDate.getHours();
  91.     var minutes = expDate.getMinutes();
  92.     var seconds = expDate.getSeconds();
  93.     var ampmIndicator = "AM";
  94.     if(hours >= 12){
  95.         ampmIndicator = "PM";
  96.     }
  97.     if(hours == 0){
  98.         hours = 12;
  99.     }else if(hours > 12){
  100.         hours = hours - 12;
  101.     }
  102.     if(minutes < 10){
  103.         minutes = "0" + minutes;
  104.     }
  105.     if(seconds < 10){
  106.         seconds = "0" + seconds;
  107.     }
  108.     return hours + ":" + minutes + ":" + seconds + " " + ampmIndicator;
  109. };
  110. /*
  111.  * Make an asynchronous call to renewSession page. 
  112.  * This is a regular JSP that does nothing, but return true
  113.  * if no Exceptions are thrown on the server side. 
  114.  * If request is successful update sessionexpiry cookie to 
  115.  * current time. 
  116.  */
  117. Timeout.prototype.extendSession = function(){
  118.     //Display error if the session has already expired
  119.     var et = this.getExpiryTime() + (alertDuration * 60 * 1000);
  120.     if(new Date().getTime() >= et){
  121.         alert("Your current session cannot be renewed as it expired at " + this.formatDate(new Date(et)));
  122.         this.sessionTimeOut();
  123.  
  124.     }
  125.     var xmlhttp;
  126.     if(window.XMLHttpRequest){
  127.           xmlhttp=new XMLHttpRequest();
  128.           alert("XMLHttpRequest="+xmlhttp);
  129.     }
  130.           else
  131.               {
  132.               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  133.               alert("ActiveXObject="+xmlhttp);
  134.     }
  135.  
  136.  
  137. //    request.open("GET",this.renewURL,true);
  138.  
  139.     /* 
  140.        Using the above renew URL approach, causes the FACES view getting
  141.        updated with the view of renew page.So after the session extension, 
  142.        the user actions in the current page doesn't really happen.
  143.     */
  144.     //var url=document.URL;
  145.     //alert("newurl="+newurl);
  146.     xmlhttp.open("GET",document.URL,true);
  147.     alert(xmlhttp.open("GET",document.URL,true));
  148.     alert("document.URL="+document.URL);
  149.     xmlhttp.onreadystatechange = function(){
  150.         if(xmlhttp.readyState==4){
  151.             alert("inside readystate=="+xmlhttp.readyState);
  152.             alert("response="+xmlhttp.responseText);
  153.             //The session was renewed if we received a HTTP response
  154.             //status of 200.  We are not interested in the actual response. 
  155.             //reset the instance of Timeout by calling start().
  156.  
  157.             if(xmlhttp.status==200){
  158.                 alert("request.status="+xmlhttp.status);
  159.                 alert("response="+xmlhttp.statusText);
  160.                 Timeout.prototype.start();
  161.             }else{
  162.                 Timeout.prototype.displayRenewError();
  163.             }
  164.         }        
  165.     };
  166.  
  167.      xmlhttp.send();
  168. };
  169.  
  170. Timeout.prototype.logout = function(){
  171.     window.location = this.logoutURL;
  172. };
  173.  
  174. Timeout.prototype.sessionTimeOut = function(){
  175.     window.location = this.sessionTimeOutURL;
  176. };
  177.  
  178. Timeout.prototype.displayRenewError = function(){
  179.     alert("Error renewing current session.\n\nPlease save your work immediately.");
  180. };
Jun 6 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.