Home >Web Front-end >H5 Tutorial >Web-side applications implement back force refresh

Web-side applications implement back force refresh

php中世界最好的语言
php中世界最好的语言Original
2018-03-27 15:44:432975browse

This time I will bring you the web-side application to implement back force refresh, and the web application to implement back force refresh. What are the precautions? The following is a practical case, let's take a look. 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(&#39;pageshow&#39;, function () { 
      if (isPageHide) { 
       window.location.reload(); 
      } 
     }); 
     window.addEventListener(&#39;pagehide&#39;, 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 reload when 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.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

The order of operating Vue rendering and plug-in loading

nodejs crawler framework superagent

How to use ueditor in vue project

The above is the detailed content of Web-side applications implement back force refresh. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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