How to make WeChat browser force refresh when returning to the previous page

Problem Description:

Jump from the home page to the details page , click the Back button on the details page to return to the home page , and then display the home page after refreshing.

Ideas:

After entering the details page , save a key-value pair in the browser, such as need-refresh : true .

After returning to the home page, retrieve this data from the browser before loading the page, and refresh if need-refresh is true .

This method avoids monitoring the return time of the WeChat browser , which is a hack method.

Note : This method requires the use of HTML5 's local storage technology , sessionStorage .

code

Details page

sessionStorage.setItem("need-refresh", true);

front page

$(function () {
    var needRefresh = sessionStorage.getItem("need-refresh");
    if(needRefresh){
        sessionStorage.removeItem("need-refresh");
        location.reload();
    }
});

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324821849&siteId=291194637