The scenario is like this: when the page is initialized, there is a button on the page, and when it is clicked, it executes window.location.reload(). Normally, after reload(), the page will still make a request to the background, but in the Android WeChat browser, the requested data after read is always the first time the page is opened. It can be understood that the request was cached, but there is no actual test, and it is not known whether it is cached.
The solution is to use window.location.href="window.location.href+random number" instead of window.location.reload(). Remember to add random numbers, otherwise they will not work. Of course, you can also use a tag, and then set href="window.location.href + random number".
If you go further, you can only make this setting for the WeChat browser, so you have to determine whether it is a WeChat browser. You can judge by window.navigator.userAgent. The result is that Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69 MicroMessenger/6.3.16. Based on the keyword MicroMessenger, determine whether it is a built-in browser for WeChat. The judgment function is as follows
function isWeiXin(){ var ua = window.navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i) == 'micromessenger'){ return true; }else{ return false; }}The above is the entire content of this article. For more information about JavaScript, you can check out: "JavaScript Reference Tutorial" and "JavaScript Code Style Guide". I also hope that everyone will support Wulin.com more.