使用其他警报覆盖/覆盖Javascript警报

时间:2013-09-20 20:08:14

标签: javascript jquery

下面是我的Javascript函数。是否可能有警报覆盖另一个警报。例如警报(消息);首先触发,但如果会话到期,则会触发警报("会话已过期。您将被重定向到登录页面");.您将看到第二个警报的唯一方法是在警报(消息)上单击“确定”。如果会话过期或以任何其他方式执行此操作,第二个警报是否可以覆盖第一个警报。

<!-- 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";
    }

1 个答案:

答案 0 :(得分:1)

这是不可能的。打开后,您无法控制对话框。 正如这个答案建议你可以尝试使用UI框架的模态对话框:Javascript close alert box

相关问题