美文网首页
ios 和 安卓在微信端点击回退让页面刷新的方法

ios 和 安卓在微信端点击回退让页面刷新的方法

作者: praycis | 来源:发表于2018-01-22 14:23 被阅读0次
function refresh(){
        //ios...
        window.onpageshow = function(e){
            if(e.persisted){
                window.location.reload();
            }
        }
        //android;
        var flag = window.sessionStorage.getItem('shouldRefresh');
        if(flag){
            window.sessionStorage.removeItem('shouldRefresh');
            window.location.reload();
        }
    }

在安卓微信端,从下一个页面跳转上一个页面的时候,需要在下一个页面加一个session标志。
ios端通过onpageshow触发。安卓通过设置sessionStorage触发。

e.persisted

  • 当值为false,说明页面是加载进来的。
  • 当值为true,说明页面时从缓存读出来的。

相关文章

网友评论

      本文标题:ios 和 安卓在微信端点击回退让页面刷新的方法

      本文链接:https://www.haomeiwen.com/subject/fqmlaxtx.html