The requirements are as follows:
1. 微信公众号点击菜单进入a页面,a页面需要获取用户昵称和头像(因此需要授权);
2.从a 页面跳到 b1,b2,b3.....页面;
3.当在 a页面时 ios手机点击左上角 “返回” 或者 其它手机物理返回键时 要求返回到微
信公众号;
But now, when no processing is done, clicking Return can only return to the WeChat Authorization page, and then after a few seconds, it will jump to page a; it is also very likely that an error will occur.
Then I will add the code to page a: the following code:
history.pushState('x-back', null);
function onPopState (event) {
WeixinJSBridge.call('closeWindow');
};
window.addEventListener('popstate', onPopState);
But there will still be problems:
安卓手机问题解决;ios碰到的问题是:从a 跳到b1 ...页面;在b1 页面ios 点左上角返回菜单时 a页面会闪一下;直接退出到公众号里面了,相当于跳过a页面;a页面 就闪了一下也就一秒;每次测试都这样;我不明白为啥从b返回到a 会触发a页面的 监听 返回键的函数。。。。
陈方2018-09-25 16:55:10
var isPageHide = false;
window.addEventListener('pageshow', function() {
if(isPageHide) {
window.WeixinJSBridge.call('closeWindow');
// window.location.reload();//Refresh yourself, this step is equivalent to simulating a jump
}
});
window.addEventListener('pagehide', function() {
isPageHide = true;
});
某草草2017-06-26 10:57:23
It is mentioned in the WeChat development documentation
2. For users who have followed the official account, if the user enters the official account's web authorization page from the official account's session or custom menu, even if the scope is snsapi_userinfo, it is silent authorization, and the user has no access Perception.
If the user has followed the official account or entered the website authorization page of the official account through a custom menu, the authorization is silent and there will be no WeChat authorization.