Here is my Javascript Function below. Is to possible to have an alert overwrite another alert. For instance alert(message); triggers first but if session expires it triggers alert("Session expired. You will be redirected to login page");. The only way you will see the second alert is if you click ok on the alert(message). Is it possible for the second alert to just overwrite the first alert if session expires or any other way of doing this.
<!-- Session Timeout Function-->
<script language="javascript" type="text/javascript">
var sessionTimeout = <%= Session.Timeout %>;
var sessionTimeoutWarning = sessionTimeout - 1;
var timeOnPageLoad = new Date();
var warning = null;
var timeout = null;
if ( <% if (MasterPageTemplate.Classes.CmwSession.IsAuthenticated) Response.Write("1"); else Response.Write("0"); %> == 1)
{
//For warning
warning = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
//To redirect to the welcome page
timeout = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);
}
//Session Warning
function SessionWarning() {
//minutes left for expiry
var minutesForExpiry = (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
var message = "Your session will expire in another " + minutesForExpiry +
" minutes! Please Save the data before the session expires";
alert(message);
var currentTime = new Date();
//time for expiry
var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));
//Current time is greater than the expiry time
if(Date.parse(currentTime) > timeForExpiry)
{
alert("Session expired. You will be redirected to login page");
window.location = "Default.aspx";
}
else
{
$.ajax({
type: "POST",
url: 'Default.aspx/PingSession',
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
success: function (msg) {
alert("Your session is now valid.")
}
});
if (warning != null)
{
clearTimeout(warning);
//For warning
warning = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
}
if(timeout != null)
{
clearTimeout(timeout);
//To redirect to the welcome page
timeout = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);
}
}
}
//Session timeout
function RedirectToWelcomePage(){
alert("Session expired. You will be redirected to login page");
window.location = "Default.aspx";
}