0

下面是我的 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";
    }

4

1 回答 1

1

这是不可能的。对话框打开后,您无法对其进行任何控制。正如这个答案所暗示的,您可以尝试使用 UI 框架的模式对话框:Javascript close alert box

于 2013-09-20T20:14:12.473 回答