码迷,mamicode.com
首页 > 微信 > 详细

js禁止浏览器,微信,及手机物理键的返回

时间:2016-01-15 14:22:59      阅读:841      评论:0      收藏:0      [点我收藏+]

标签:

XBack = {};

(function(XBack){
XBack.STATE = ‘x-back‘;
XBack.element;

XBack.onPopState = function(event){
event.state === XBack.STATE && XBack.fire();
XBack.record(XBack.STATE); //初始化事件时,push一下
};

XBack.record = function(state){
history.pushState(state, null, location.href);
};

XBack.fire = function(){
var event = document.createEvent(‘Events‘);
event.initEvent(XBack.STATE, false, false);
XBack.element.dispatchEvent(event);
};

XBack.listen = function(listener){
XBack.element.addEventListener(XBack.STATE, listener, false);
};

XBack.init = function(){
XBack.element = document.createElement(‘span‘);
window.addEventListener(‘popstate‘, XBack.onPopState);
XBack.record(XBack.STATE);
};

})(XBack); // 引入这段js文件

在所需要的页面上使用 

XBack.init();
XBack.listen(function(){});

 

js禁止浏览器,微信,及手机物理键的返回

标签:

原文地址:http://www.cnblogs.com/smallTao/p/5132983.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!