history-back
;!function(pkg, undefined){ //此声明函数在xback.js文件里有,在app.js里必须再声明一次,不然监听返回事件失败
var STATE = 'x-back';
var element;
var onPopState = function(event){
event.state === STATE && fire();
record(STATE); //初始化事件时,push一下
}
var record = function(state){
history.pushState(state, null, location.href);
}
var fire = function(){
var event = document.createEvent('Events');
event.initEvent(STATE, false, false);
element.dispatchEvent(event);
}
var listen = function(listener){
element.addEventListener(STATE, listener, false);
}
!function(){
element = document.createElement('span');
window.addEventListener('popstate', onPopState);
this.listen = listen;
//record(STATE); //注释掉这行代码
}.call(window[pkg] = window[pkg] || {});
}('XBack');
var STATE = "x-back"
history.pushState(STATE, null, location.href);
window.onpopstate = function(event) {
if(event.state === STATE) {
if (opt.callback && typeof opt.callback == 'function') {
opt.callback();
}
}
};