Perfect solution to the problem that IOS wechat browser does not refresh when it returns

Time:2021-11-29

When the form is submitted at the beginning, the returned parameters will be lost. Replace it with URL jump. There is always a problem in the ios10 test. Continue to search. Finally, use pageshow and pagehide to solve it perfectly (another sentence: cherish life and stay away from wechat and IOS)

var wxback = {
    init :function(){
      //Hide wechat sharing buttons, etc
      document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideToolbar');
        WeixinJSBridge.call('hideOptionMenu');
        WeixinJSBridge.call('hideMenuItems');
      });
      if(getSystem()=="ios"){
        //this.pushHistory();
        /*Window. Addeventlistener ("pop state", function (E) {// implement the required functions in the callback function
          //window.location.href = document.referrer+"&"+Math.floor(Math.random()*1000);
          //history.go(-1);// Anyway, I returned to the original page n times
          //history.back();// Anyway, I returned to the original page n times
          //window.location = document.referrer;// Previous page URL
          //WeixinJSBridge.call('closeWindow');// Close page directly
        }, false);*/
        var isPageHide = false; 
        window.addEventListener('pageshow', function () { 
         if (isPageHide) {
          window.location.reload(); 
         } 
        }); 
        window.addEventListener('pagehide', function () { 
         isPageHide = true; 
        }); 
      }
    },
    pushHistory :function () {
      var state = { 
        title: document.title, 
        url: location.href 
      }
      window.history.pushState(state, state.title, state.url); 
      console.log(window.history);
    },
}

summary

The above is the perfect solution to the non refresh problem of IOS wechat browser. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time!

Recommended Today

On the mutation mechanism of Clickhouse (with source code analysis)

Recently studied a bit of CH code.I found an interesting word, mutation.The word Google has the meaning of mutation, but more relevant articles translate this as “revision”. The previous article analyzed background_ pool_ Size parameter.This parameter is related to the background asynchronous worker pool merge.The asynchronous merge and mutation work in Clickhouse kernel is completed […]