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

    if (location.hostname === 'activity.yoho.cn') {
        state.url = '//activity.yoho.cn/api/wechat/download';
    } else if (location.hostname === 'm.yohobuy.com') {
        state.url = '//m.yohobuy.com/api/wechat/download';
    } else {
        return false;
    }

    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();
}