Home >Web Front-end >JS Tutorial >Web side implements back force refresh function code
This article mainly introduces to you the implementation code of the back force refresh function on the WeChat web side. Friends who need it can refer to it. I hope it can help everyone.
The specific code is as follows:
<script> //生成uuid var uuidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""); function uuid() { var r; var uuid = []; uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-"; uuid[14] = "4"; for (i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | Math.random() * 16; uuid[i] = uuidChars[(i == 19) ? (r & 0x3) | 0x8 : r]; } } return uuid.join(""); } // 兼容 android history.replaceState(null, null, "/currentURL?a="+uuid()); // 兼容 ios $(function () { var isPageHide = false; window.addEventListener('pageshow', function () { if (isPageHide) { window.location.reload(); } }); window.addEventListener('pagehide', function () { isPageHide = true; }); }) </script>
•The history object in h5 used by the android side, history.replaceState(null, null, "/currentURL?a= "+uuid());
Change the current url (splicing a uuid or random number) after the page is loaded, so that every time you go back, the browser will find that the current url does not exist in the browser cache and will re- load.
•But the ios side does not support the above method, so I used a piece of jquery code to solve it.
Related recommendations:
javascript code to force refresh the page_javascript skills
The above is the detailed content of Web side implements back force refresh function code. For more information, please follow other related articles on the PHP Chinese website!