給瀏覽器添加歷史記錄,並監聽是否進行回退操作
returnHistory:function returnHistory(){
var state = {
title: "title",
url: "#"
};
window.addEventListener("popstate", function(e) {
if( window.confirm('你確定要離開網站嗎?') ){
WeixinJSBridge.call("closeWindow");
}
});
window.history.pushState(state, "title", "#");
}
判斷是否在ios和Android中
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i) || navigator.userAgent.match(/android/i)) {}