C# 禁用浏览器后退按钮javascript
我正在使用MVC4和java脚本 今天的我有一个要求,在所有浏览器中禁用后退按钮,需要防止在浏览器的后退按钮的帮助下单击注销按钮后返回上一页(主页) 帮帮我,谢谢。试试这个 JavaScript代码示例 我们需要禁用浏览器后退按钮的所有页面的javascript代码C# 禁用浏览器后退按钮javascript,c#,javascript,asp.net-mvc-4,C#,Javascript,Asp.net Mvc 4,我正在使用MVC4和java脚本 今天的我有一个要求,在所有浏览器中禁用后退按钮,需要防止在浏览器的后退按钮的帮助下单击注销按钮后返回上一页(主页) 帮帮我,谢谢。试试这个 JavaScript代码示例 我们需要禁用浏览器后退按钮的所有页面的javascript代码 <script type="text/javascript"> //Disable Back Button In All Browsers. function DisableBackBut
<script type="text/javascript">
//Disable Back Button In All Browsers.
function DisableBackButtonAllBrowsers() {
window.history.forward()
};
DisableBackButtonAllBrowsers();
window.onload = DisableBackButtonAllBrowsers;
window.onpageshow = function (evts) { if (evts.persisted) DisableBackButtonAllBrowsers(); };
window.onunload = function () { void (0) };
</script>
//在所有浏览器中禁用后退按钮。
函数disableBackbuttonalBrowsers(){
window.history.forward()
};
禁用BackButtonalBrowser();
window.onload=禁用BackbuttonalBrowser;
window.onpageshow=函数(evts){if(evts.persisted)disablebackbuttonalbrowsers();};
window.onunload=函数(){void(0)};
MVC4中的ActionResult代码示例
用于在MVC4中响应注销操作结果的代码。i、 e
/// <summary> /// Logs user out and renders login <see cref="View"/> /// </summary> /// <returns>Login <see cref="View"/></returns>
public ActionResult Logout()
{
//Disable back button In all browsers.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
FormsAuthentication.SignOut();
return View("Login");
}
////注销用户并呈现登录////////登录
公共操作结果注销()
{
//在所有浏览器中禁用后退按钮。
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
FormsAuthentication.SignOut();
返回视图(“登录”);
}
试试这个,也许会对你有所帮助
链接:
Javascript代码:
<script type = "text/javascript" >
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>
函数preventBack(){window.history.forward();}
setTimeout(“preventBack()”,0);
onunload=function(){null};
您可以按如下方式使用:
<script type="text/javascript" language="javascript">
function DisableBackButton() {
window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function(evt) { if (evt.persisted) DisableBackButton() }
window.onunload = function() { void (0) }
</script>
函数DisableBackButton(){
window.history.forward()
}
禁用BackButton();
window.onload=禁用BackButton;
window.onpageshow=函数(evt){if(evt.persisted)DisableBackButton()}
window.onunload=function(){void(0)}
可能重复。。
这里提到了一个解决方案:
set cachebality to noCache..
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
理想情况下,首先要防止填充会话历史记录
location.replace(url)
发件人:
Location.replace()方法将当前资源替换为所提供URL上的资源。使用replace()后,当前页面将不会保存在会话历史记录中,这意味着用户将无法使用“上一步”按钮导航到该页面
如果会话历史记录为空,则禁用“后退”按钮。如果您的应用程序严重依赖表单提交,jQuery可以轻松地将表单变量转换为查询字符串,以便与location.replace一起使用
function submitForm() {
// this eliminates issues with the back button
window.location.replace('?' + jQuery.param(jQuery('form').serializeArray()));
}