back-download.js
1.11 KB
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
// 微信返回注册下载事件
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 || window.__wxjs_environment === 'miniprogram') {
return false;
}
try {
window.history.replaceState(state, null, state.url);
window.history.pushState({page: pages[1]}, null, url);
} catch (e) {
return;
}
}
if (/micromessenger/i.test(navigator.userAgent) &&
document.getElementById('main-wrap').getAttribute('data-backDownload')) {
pushHistory();
}