ExpiredSessionPopup

by Jose Montero

HTML

<div id="expiredWindow">
Your Session will expire in 1 minute! Click, "OK" button to continue your application!
<button>OK</button>
</div>
<div id="modal" style="border:3px solid black; background-color:#9999ff; padding:25px; font-size:150%; text-align:center; display:none;">
	This is a modal popup!<br><br>
	<input type="button" value="OK" onClick="Popup.hide('modal')">
</div>

CSS

div#expiredWindow{
  display: none;
}

JavaScript

var timeout = (function(){
	
	return{
  seconds	: 0,
  	currentTime	: new Date(),
		futureDate : new Date(),
    counter : 0,
    stopIt		: '',
  	init : function()
    {
    	this.seconds = 0;

    //console.log(this.today);
     	this.currentTime = new Date();
     	this.futureDate = this.currentTime.getTime() + (1 * 60 * 1000);
      
      console.log("FUTURE DATE : "+new Date(this.futureDate));
    	this.stopIt = setInterval(function() { this.expiredSession(); }.bind(this), 1000);			
    },
    expiredSession : function()
    {
     	
      try
      {
        this.counter++;
        this.seconds = this.seconds + 1000;
        var today = this.currentTime;
        today = new Date(this.currentTime.getTime() + this.seconds);
          console.log(this.counter+": TIME: "+today +", FUTURE TIME: "+new Date(this.futureDate));
        if (today.getTime() === this.futureDate)
        {
          clearInterval(this.stopIt);
          alert('Expired');
        }  
        else if (this.counter == 60)
        {
          clearInterval(this.stopIt);
          console.log("Counter: "+this.counter);
          console.log("today.getTime() === this.futureDate: "+(today.getTime() === this.futureDate));
        }
       }
       catch(error)
       {
       	 console.log("Error: "+error);
        clearInterval(this.stopIt);
       }
    }
    
  }
	
})();
timeout.init();