javascript - Questions about WeChat authorization.
过去多啦不再A梦
过去多啦不再A梦 2017-05-31 10:40:12
0
2
725

I now have a list page. When the product is clicked on the list page to enter the details page, WeChat authorization begins. After the authorization is successful, it is redirected to the current details page. Then click the return button of WeChat, and the official page authorized by WeChat will still be returned (as shown in the figure below). Then it redirects me to my details page, which means I can’t go back to the list page. Can anyone help me with the answer?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
左手右手慢动作

I have been working on a WeChat public account recently, and there is also a need for WeChat authorization. However, maybe because I am on the first-level page, I authorize it directly after entering, so your problem is not exposed. Here are some personal opinions, there must be shortcomings, please correct me:
First of all: WeChat’s back button is directly related to the history of its browser. In my case, it is authorized directly after entering the first-level page. Then if the user directly clicks back, it will achieve the effect of "closing the page and displaying the main menu". I have tried several methods, including:

"Listen for return events"

window.addEventListener("popstate", function()
{
    //监听到后执行的代码
},false);

"After authorized login, use the history built-in method"

window.history.go(-1);
或
window.history.back

However, there have been many situations where the WeChat WEB developer tool works, but not on the mobile version; or it works at the time, but fails again after two days.
Solution: In the end, I still used the new features of h5

//替换(用null模拟删除)url记录,实现返回一级页面 直接关闭
window.history.replaceState(null, null, toUrl);

It is equivalent to leaving the login interface record blank in the browser history.
You can try this, it may be useful to you,,,,

巴扎黑

In fact, in WeChat, everythingauthorized on demand is rogue; the experienceis extremely poor.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!