需求场景:
只有扫码初始进入异业联盟活动页,0元券直接弹框领取成功(如图1)
抛出问题:
- 进入优惠券包后到另一个页面(如图1)
- 然后按手机返回会回到异业联盟活动页,始终弹出领取活动页面
解决方案:
在优惠券包页面中监听手机返回事件,直接关闭页面退出到公众号
1、微信jssdk(closeWindow)
let sign_url = window.location.href.split('#')[0];
sign(sign_url).then((res)=>{
let configData = {
debug: false,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: ['closeWindow']
}
console.log(configData)
wx.config(configData)
}).catch((err)=>{
})
2、通过监听popstate事件,来判断是否点击返回按钮,调用wx.closeWindow方法
window.addEventListener("popstate", (e) => {
wx.closeWindow();
}, false);