javascript倒计时跳转(调用asp.net变量url)

时间:2021-05-16 22:05:51

例:===========Logout.aspx 页============================

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language='javascript' type='text/javascript'>
var secs =5; //倒计时的秒数
var URL;
function Load(url) {
URL = url;
for(var i=secs;i>=0;i--)
{
window.setTimeout('doUpdate(' + i + ')', (secs-i) * 1000);
}
}
function doUpdate(num)
{
document.getElementById('msg').innerHTML = '您已经退出登录,将在' + num + '秒后返回';
if(num == 0) { window.location=URL; }
}
</script>
</head>
<body>
<form id="form1" runat="server">

<div id="msg" style="margin:20px auto;"></div>

<script language='javascript' type='text/javascript'>
Load("<% = GetReturnUrl() %>");  

<!---这里调用的asp.net方法,也可以在这里直接写出url地址-->
</script>


</form>
</body>
</html>

 

 

===========Logout.aspx.cs 页============================

 

        protected void Page_Load(object sender, EventArgs e)
        {
            Session.Clear();
            Session.RemoveAll();
            System.Web.Security.FormsAuthentication.SignOut();
        } 

 

        protected string GetReturnUrl()
        {
            if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
            {
                return "/"; 
            }
            else
            {
                return Request.QueryString["ReturnUrl"];
            }
       
}