禁用浏览器后退按钮javascript

禁用浏览器后退按钮javascript

本文介绍了禁用浏览器后退按钮javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Java脚本的MVC 4.

I am using MVC 4 with java script.

今天,我需要在所有浏览器中禁用返回"按钮,在浏览器的返回"按钮的帮助下单击注销按钮后,需要防止返回上一页(主页).

Today's i have a requirement to disable to back button in all browsers, need to prevent to go-back to previous page(home page) after click on log-out button with the help of back button of browsers.

帮我谢谢.

推荐答案

尝试一下

JavaScript代码示例

JavaScript Code Sample

在所有需要禁用浏览器后退按钮的页面上的javascript代码.

javascript code to all the pages where we need to disable the browser back button.

<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>

Mvc 4中的ActionResult代码示例

ActionResult code sample in mvc 4

用于响应ActionResult以在MVC 4中注销的代码,即

Code for response to ActionResult for log-out in MVC 4. 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");
     }

这篇关于禁用浏览器后退按钮javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:41