2014-12-30 67 views
1

我正在使用一個js文件,它在用戶會話即將結束之前給了我一個彈出窗口。我用2種方式使用這個文件無法調用js文件功能

1)在web表單應用程序 - 它工作得很好。以下是它的代碼。 我下面this鏈接

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 



<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Session Time Out Warning Message</title> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> 

    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script> 

    <script src="Script/timeout-dialog.js" type="text/javascript"></script> 

    <link href="css/timeout-dialog.css" rel="stylesheet" type="text/css" /> 

    <script type="text/javascript" language="javascript"> 

     function Timer(time) { 

      setTimeout(TimeOut, time); 
     } 

     function TimeOut() { 
      alert(window.location.pathname); 
      $.timeoutDialog({ 
       timeout: 0.15, 
       countdown: 60, 
       keep_alive_url: window.location.pathname, 
       logout_redirect_url: '/AutoSessionTimeOut/SessionTime.aspx', 
       restart_on_yes: true 
      }); 
     } 

    </script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label> 
    </div> 
    </form> 
</body> 
</html> 

CS代碼:

if (!IsPostBack) 
     { 
      int _displayTimeInMiliSec = (Session.Timeout - 1) * 60000; 

      if (Session["ID"] == null) 
      { 
       Session["ID"] = "New Session"; 
       lblMsg.Text = Convert.ToString(Session["ID"]); 
      } 
      else 
       lblMsg.Text = "Old Session"; 

      ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), 
       "message", 
       "<script type=\"text/javascript\" language=\"javascript\">Timer('" + _displayTimeInMiliSec + "');</script>", 
       false); 
     } 

2)我的MVC應用程序中使用它。

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>@ViewBag.Title - My ASP.NET Application</title> 
    @Styles.Render("~/Content/css") 
    @Scripts.Render("~/bundles/modernizr") 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script> 

    <script src="Scripts/timeout-dialog.js"></script> 
    <link href="Content/timeout-dialog.css" rel="stylesheet" /> 
    <script type="text/javascript"> 

     function Timer(time) { 

      setTimeout(TimeOut, time); 
     } 

     function TimeOut() { 
      //window.location.pathname = '/Home/Index'; 
      alert(window.location.pathname); 
      alert('hi'); 
      $.timeoutDialog({ 
       timeout: 0.25, 
       countdown: 30, 
       keep_alive_url: window.location.pathname, 
       logout_redirect_url: '/Home/Index', 
       restart_on_yes: true 
      }); 

     } 


    </script> 



</head> 
<body onload="Timer(15000)"> 

    <div class="navbar navbar-inverse navbar-fixed-top"> 
     <div class="container"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 
       @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" }) 
      </div> 
      <div class="navbar-collapse collapse"> 
       <ul class="nav navbar-nav"> 
        <li>@Html.ActionLink("Home", "Index", "Home")</li> 
        <li>@Html.ActionLink("About", "About", "Home")</li> 
        <li>@Html.ActionLink("Contact", "Contact", "Home")</li> 
       </ul> 
       @Html.Partial("_LoginPartial") 
      </div> 
     </div> 
    </div> 
    <div class="container body-content"> 
     @RenderBody() 
     <hr /> 
     <footer> 
      <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p> 
     </footer> 
    </div> 

    @Scripts.Render("~/bundles/jquery") 
    @Scripts.Render("~/bundles/bootstrap") 
    @RenderSection("scripts", required: false) 
</body> 
</html> 

在這裏,當我把警報只是這一行$.timeoutDialog({如上面提到的前,警報自帶但是代碼的其他部分並沒有執行,我沒有得到我在我的web應用程序的形式得到任何彈出窗口。

什麼,我在MVC應用做錯了。請幫忙。

+0

整數? – Shiljo

+0

@Shil:我如何檢查。 – user2998990

+0

請如果您使用的Chrome網絡瀏覽器,使用控制檯調試在Chrome或IE瀏覽器的代碼 – Shiljo

回答

0

我覺得timeout參數應該就是所有的JS文件越來越加載提到here

+0

我試圖把1200,仍然沒有工作。 – user2998990

+0

我只是不理解,相同的代碼可以在鏈接中正常工作,但在mvc中不起作用。 – user2998990