Home Web Front-end JS Tutorial How to implement the back force refresh function on WeChat web side (detailed tutorial)

How to implement the back force refresh function on WeChat web side (detailed tutorial)

Jun 01, 2018 pm 03:14 PM
web force new function

This article mainly introduces the implementation code of the back force refresh function on the WeChat web side. Friends who need it can refer to it

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>
Copy after login

•The history object in h5 used by the android side, history.replaceState(null, null, "/currentURL?a=" uuid()); changes after the page is loaded The current url (spliced ​​with a uuid or random number), so that every time you go back, the browser will reload if it finds that the current url does not exist in the browser cache.
•But the ios side does not support the above method, so I used a piece of jquery code to solve it.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

vue axios request interception example code

Use vue2 to implement shopping cart and address selection functions

Angular development practice server-side rendering

The above is the detailed content of How to implement the back force refresh function on WeChat web side (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iPadOS18 new features iPadOS18 new features Jun 12, 2024 pm 10:41 PM

iPadOS18 new features

WeChat launches new feature: 'Quiet Mode” WeChat launches new feature: 'Quiet Mode” Mar 04, 2024 pm 01:43 PM

WeChat launches new feature: 'Quiet Mode”

How to completely restore or force restore all iPhone 15 models to factory settings How to completely restore or force restore all iPhone 15 models to factory settings Sep 23, 2023 pm 02:41 PM

How to completely restore or force restore all iPhone 15 models to factory settings

Microsoft Edge browser's new feature 'Super Drag” is now available! Microsoft Edge browser's new feature 'Super Drag” is now available! Mar 04, 2024 pm 06:31 PM

Microsoft Edge browser's new feature 'Super Drag” is now available!

Using Jetty7 for Web server processing in Java API development Using Jetty7 for Web server processing in Java API development Jun 18, 2023 am 10:42 AM

Using Jetty7 for Web server processing in Java API development

How to implement form validation for web applications using Golang How to implement form validation for web applications using Golang Jun 24, 2023 am 09:08 AM

How to implement form validation for web applications using Golang

How to enable administrative access from the cockpit web UI How to enable administrative access from the cockpit web UI Mar 20, 2024 pm 06:56 PM

How to enable administrative access from the cockpit web UI

Is PHP front-end or back-end in web development? Is PHP front-end or back-end in web development? Mar 24, 2024 pm 02:18 PM

Is PHP front-end or back-end in web development?

See all articles