Javascript 如何在aspx中禁用后退按钮?
这是我的密码:Javascript 如何在aspx中禁用后退按钮?,javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,这是我的密码: protected void btnresult_Click(Object sender, EventArgs e) { Button btn = (Button)(sender); Response.Write("<script>"); Response.Write("window.open('studentresult.aspx?id=" + btn.CommandArgument + "','_blank')"); Response.Wr
protected void btnresult_Click(Object sender, EventArgs e)
{
Button btn = (Button)(sender);
Response.Write("<script>");
Response.Write("window.open('studentresult.aspx?id=" + btn.CommandArgument + "','_blank')");
Response.Write("</script>");
}
protectedvoid btnresult\u单击(对象发送方,事件参数e)
{
按钮btn=(按钮)(发送器);
回答。写(“”);
Response.Write(“window.open('studentresult.aspx?id=“+btn.CommandArgument+”,'u blank');
回答。写(“”);
}
我的主页studentry.aspx
在我的主页中,当我单击结果按钮时,它会转到新窗口页面,并显示学生结果
但在这之后,我会看看主页,它会显示在url地址栏顶部的后退按钮
所以我点击后退按钮,它再次进入新窗口页面并显示学生结果
我可以知道,当我单击“结果”按钮时,为什么“后退”按钮处于活动状态吗?在页面代码隐藏文件中写入下面的方法,并在页面加载事件中调用它
public void disablebrowserbackbutton()
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoServerCaching();
HttpContext.Current.Response.Cache.SetNoStore();
}
在
标记内的客户端文件(html
)中添加以下脚本,或者在内容占位符之前使用母版页
<script type="text/javascript">
function preventBack() {
window.history.forward();
}
setTimeout("preventBack()", 0);
window.onunload = function() {
null
};
函数preventBack(){
window.history.forward();
}
setTimeout(“preventBack()”,0);
window.onunload=函数(){
无效的
};
以上代码的目标是空白,因此打开浏览器的新选项卡时,默认情况下会禁用“上一步”按钮,这可能会引导您在默认情况下禁用新选项卡。。但在我的家里,点击“返回”按钮……试试上面评论中的链接,可能会有所帮助you@VijayKumbhoje:实际上,我正在努力从您的链接在现有代码中添加代码。。