back-download.js 817 Bytes
// 微信返回注册下载事件
function pushHistory() {
    var pages = ['yh_download', 'yh_forward'];
    var state = {
        title: '下载页面',
        page: pages[0],
        url: '//m.yohobuy.com/api/wechat/download'
    };
    var url = location.href;

    window.addEventListener('popstate', function(e) {
        var temp = e.state;

        if (temp && pages.indexOf(temp.page) > -1) {
            location.reload();
        }
    });

    if (!window.history.pushState || window.history.length > 1) {
        return false;
    }

    window.history.replaceState(state, null, state.url);
    window.history.pushState({page: pages[1]}, null, url);
}

if (/micromessenger/i.test(navigator.userAgent) &&
    document.getElementById('main-wrap').getAttribute('data-backDownload')) {
    pushHistory();
}