禁用特定url的浏览器后退按钮
Disabling browser back button for specific url
我想禁用浏览器返回按钮,或者说不想让用户从特定的url导航回来。假设url是:
http://localhost/emptracker/#setup
所以我想要的是,当用户来到这个网址时,后退按钮应该被禁用。目前,我阅读了许多Stack Overflow的帖子,并尝试了类似的解决方案
<script type="text/javascript">
history.pushState(null, null, 'pagename');
window.addEventListener('popstate', function(event) {
history.pushState(null, null, 'pagename');
});
</script>
但问题是,它禁用了整个应用程序中url的后退按钮,我想对特定的url执行此操作。我的应用程序是基于backbonej的。
使用它。我认为这对你有帮助
file1.html:
<form action="page2.html#no-back" method="post" />
<input type="text" name="data" value="The data" />
<input type="submit" value="Send data" />
</form>
file2.html
// It works without the History API, but will clutter up the history
var history_api = typeof history.pushState !== 'undefined'
// The previous page asks that it not be returned to
if ( location.hash == '#no-back' ) {
// Push "#no-back" onto the history, making it the most recent "page"
if ( history_api ) history.pushState(null, '', '#stay')
else location.hash = '#stay'
// When the back button is pressed, it will harmlessly change the url
// hash from "#stay" to "#no-back", which triggers this function
window.onhashchange = function() {
// User tried to go back; warn user, rinse and repeat
if ( location.hash == '#no-back' ) {
alert("You shall not pass!")
if ( history_api ) history.pushState(null, '', '#stay')
else location.hash = '#stay'
}
}
}
访问本文工作文件
或
通过在线演示访问本文
相关文章:
- 当浏览器上的后退按钮到达主页时,我需要删除Class
- 如何使用手机浏览器上的按钮拨打USSD代码
- 单击按钮即可在浏览器的新选项卡中打开 Sapui5 详细信息页面
- 如何在用户按下F5键或单击浏览器时显示自定义的fancybox's后退/关闭按钮
- 链接/按钮从子文件夹下载文件--浏览器只是浏览
- '返回'浏览器按钮返回白色页面
- ReactJS:使用浏览器按钮导航时保存状态
- 禁用浏览器按钮,直到页面加载完成
- 如何更改浏览器按钮名称
- 如何绑定“退出全屏f11”浏览器按钮
- 是否存在检测最后一次导航事件是否由后退或前进浏览器按钮引起的方法
- 当用户带着浏览器按钮返回时,提醒推荐人
- 如何过期网页时,后退/前进从浏览器按钮
- 要更改默认文本"No File Selected"在JSP中添加一些其他文本的浏览器按钮
- 使用ui-routing进行分页.返回(下一个)浏览器按钮没有重新加载控制器
- 是否有可能显示模态框,只有当用户点击关闭选项卡/浏览器按钮
- Android浏览器按钮单击“发布”
- 禁用所有主要浏览器中的浏览器按钮和url地址栏
- 如何显示消息,如果用户单击浏览器按钮
- 如何在服务器端显示消息,如果我点击浏览器按钮