assume default home page is default.aspx, default first page is default.htm.
default.htm:
<script type="text/javascript" language="javascript">
<!--
setTimeout('OpenWin()', 100);
function OpenWin()
...{
if(window.parent != null && window.opener == null)
...{
window.parent.location = "Default.aspx";
}
else if(window.opener != null && !window.opener.closed)
...{
window.opener.location = "default.htm"; // recursion to close opener's opener's opener...
window.close();
}
else
...{
window.location = "Default.aspx";
}
}
//-->
</script>
code to redirect to default.htm:
private void ResponseRidirect()
...{
string currentUrl = this.Request.Url.ToString();
string appPath = this.Request.ApplicationPath;
int index = currentUrl.IndexOf(appPath);
string destUrl = string.Format("{0}/default.htm", currentUrl.Substring(0, index + appPath.Length));
string script = "<script language="javascript" type="text/javascript"> " +
"window.location = "" + destUrl + ""; " +
"</script>";
Response.Write(script);
Response.End();
}
本文介绍了一个使用JavaScript进行页面重定向的技巧,同时提供了一个C#的ASP.NET示例来实现从当前页面重定向到默认首页的过程。通过检测窗口的状态,可以确保用户被正确地引导到所需的默认页面。
1万+

被折叠的 条评论
为什么被折叠?



