使用html5 history实现微信端,再按一次返回按钮 返回微信 http://m.blog.csdn.net/article/details?id=52084383
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
if(window.history.length==1){//判断是第一次从微信菜单进入页面 //写入空白历史记录 pushHistory(); } //延时监听 setTimeout(function () { //监听物理返回按钮 window.addEventListener("popstate", function(e) { alert("sfd"); layer.open({ content: '您确定要返回微信吗?', btn: ['确认', '再逛逛'], shadeClose: false, yes: function(){ //调用微信浏览器私有API关闭浏览器 WeixinJSBridge.call('closeWindow'); }, no: function(){ //点击【再逛逛】,再次写入空白历史记录 pushHistory(); } }); }, false); }, 300); /** * [pushHistory 写入空白历史记录] * @author 邱先生 * @copyright 烟火里的尘埃 * @version [V1.0版本] * @date 2016-07-30 * @return {[type]} [description] */ function pushHistory() { var state = { title: "title", url: "#" }; window.history.pushState(state, "title", "#"); } |