禁用一页应用程序的浏览器后退按钮 [英] Disable browser back button for one page application

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

问题描述

我需要在单页面应用程序中禁用浏览器的后退按钮。
我尝试使用 onhashchange window.history.forward 等方法,但它们不起作用(原因可能是这里的网址没有更改)
请帮忙!
谢谢。

I need to disable the back button of browser in my single page application. I tried using methods like onhashchange or window.history.forward but they don't work (reason may be that url doesn't get changed here) Please help! Thanks.

推荐答案

我在AngularJS工作,构建单页应用程序,我想禁用或阻止后退按钮浏览器,因为我的应用程序有按钮和锚点,所有navegation进入我的应用程序。

I work in AngularJS building a Single Page App and I wanted to disable or prevent the back button of the browser, because my app has buttons and anchors for all navegation into my app.

我搜索并测试了很多代码,这是很容易防止后退按钮浏览器和以下代码对我有效。

I searched and test many codes, and this is the easy to prevent the back button of browsers and the following code worked for me.


window.onpopstate = function(e){
window.history.forward (1); }

window.onpopstate = function (e) { window.history.forward(1); }

当历史记录检测到第一个history.back()

When the history detects the first history.back()


window.onpopstate

window.onpopstate

执行,然后在此时刻之后检测到历史记录中的任何后退或前进事件。

is executed, then after this moment any back or forward in history are detected for onpopstate event.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆