直接来个终极方案:

查找了好多资料才找到的,这种方式,可以消除 后退的所有动作。包括 键盘、鼠标手势等产生的后退动作。

<script language="javascript">
//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
</script>

现在,我们项目中就使用了这种方式。在常用浏览器中,都可以禁用了后退。

具体实例:

$(function(){
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', forbidBack);
}
})
/**
* 禁止回退按钮
*/
function forbidBack(){
appUtils.mobileConfirm("确定放弃重置密码?",function(){//yes
window.removeEventListener('popstate',forbidBack);
muiwindow.muiwebview({"url":"login.html"});
},function(){//no
//防止页面后退
history.pushState(null, null, document.URL);
});
}

PS:关于addEventListener与removeEventListener的注意事项可参考: http://www.cnblogs.com/JsonShare/p/6737499.html

关于HTML5 history新特性pushState、replaceState : http://blog.csdn.net/tianyitianyi1/article/details/7426606

最新文章

  1. 如何在虚拟机里安装Linux
  2. postgresql:pgadmin函数调试工具安装过程
  3. 2016暑假多校联合---Windows 10
  4. 在ASP.NET中实现OAuth2.0(一)之了解OAuth
  5. iptables规则表
  6. hdu 3996 (最大权闭合图)
  7. Android MVP模式
  8. tomcat下配置https环境
  9. jQuery之事件
  10. iis的web站点配置
  11. 修改tomcat图标
  12. nvarchar 和varchar区别
  13. MYSQL 子查询返回多列显示
  14. asp.net core 系列之webapi集成EFCore的简单操作教程
  15. 图的BFS----迷宫问题
  16. js中的简单数据类型和复杂数据类型的存储
  17. openstack之neutron配额调整
  18. 用powermock 方法中new对象
  19. ffmpeg文件切片
  20. (6)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- AOP框架

热门文章

  1. 《Vue2.0 实践揭秘》终于出版啦!
  2. 篇3 安卓app自动化测试-搞定界面元素
  3. FrameBuffer系列 之 显示图片
  4. HTML5的article和section的区别
  5. postgres导入其他数据库数据
  6. 最新合购网源码net.asp程序 彩票合买功能采用全新内核、全新架构,更小巧、功能更强、更快、更安全稳定
  7. 6.1熟知tsung.xml配置文件(翻译)
  8. Memcache服务搭建
  9. SSH抛出org.apache.ibatis.exceptions.PersistenceException: 异常
  10. struts2.5能不能再恶心点