//微信回退事件的监听 var listenerBackHandler = { param: { isRun: false, }, listenerBack: function () { var state = { title: "title", url: "#" }; window.history.pushState(state, "title", "#"); window.addEventListener("popstate", function (e) { if (listenerBackHandler.param.isRun) { if (window.location.pathname === '/index/book/chapter') { $.fn.cookie('back', 'read', {path: '/'}); $.fn.cookie('pre_chapter_idx', window.map.chapter_idx, {path: '/'}); } listenerBackHandler.param.isRun = false; cpslog([703, {}, 'back'], function () { if (window.history.length <= 2) { WeixinJSBridge.call('closeWindow'); }else{ window.history.go(-2); } }); } },false); }, initBack: function () { window.addEventListener('pageshow', function () { if ($('.return_popup_box').length > 0) { if ($.fn.cookie('back') === 'read' && !$.fn.cookie('return_close_but') && window.history.length > 1) { $.ajax({ url:'/index/book/getreturnchapterbook', xhrFields: { withCredentials: true }, type:'post', success:function(result){ if (result.data) { $('.return_box div a').attr('href', result.data.url).attr('data-book_id', result.data.id); $('.return_tit a').text(result.data.name); $('.return_p a').text(result.data.description); $('.return_img img').attr('src', result.data.image); $('.return_popup_box').removeClass('hide'); cpslog([701, {map: {pre_chapter_idx: $.fn.cookie('pre_chapter_idx')}}]) } }, error:function(){ console.log('error'); } }) }else{ $('.return_popup_box').addClass('hide'); } } $.fn.cookie('back', '', {path: '/'}); listenerBackHandler.param.isRun = false; setTimeout(function () { listenerBackHandler.param.isRun = true; }, 600); //延迟1秒 防止微信返回立即执行popstate事件 listenerBackHandler.listenerBack(); }); } } $(function () { listenerBackHandler.initBack(); $('.return_close_but').click(function () { $.fn.cookie('return_close_but', 1, {expires: 0.33, path: '/'}); $('.return_popup_box').addClass('hide'); }); $('.url_link').click(function () { $.fn.cookie('return_close_but', 1, {expires: 0.33, path: '/'}); $('.return_popup_box').addClass('hide'); cpslog([702, { map: { box_book_id: commont.getQueryString('book_id'), pre_chapter_idx: $.fn.cookie('pre_chapter_idx') } }, 'return_link']); }); });