• 移动端页面返回强制刷新页面


    返回不刷新是因为,移动端浏览器为了节省流量一般返回都会去缓存,可以通过页面显示事件监听页面返回,通过event.persisted字段来判断当前页面是否是从缓存中获去的

    window.addEventListener('pageshow', function (event) {
    //event.persisted属性为true时,表示当前文档是从往返缓存中获取
      if (event.persisted) location.reload();
     });
    

    实际测试发现,返回时页面显示事件虽然执行,但是location.reload()并没有效果,页面仍然没有刷新,尝试通过元控制当前页面不缓存,仍然失败。

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    

    华为尝试发现计时器刷Nova4e不兼容,其他浏览器外部其他ok
    最终代码

    function reload(){
        setTimeout(function() {
            location.reload()
        }, 500);
    }
    
    window.addEventListener('pageshow', function (event) {
        //event.persisted属性为true时,表示当前文档是从往返缓存中获取
        if (event.persisted) {
            reload();
        }
    });
    

    注:以上方案来自团队小伙伴贡献,记录下来,方便以后查阅

  • 相关阅读:
    springmvc与ajax交互
    [PAT] A1052 Linked List Sorting
    [PAT] A1032 Sharing
    [PAT] A1076 Forwards on Weibo
    [PAT] A1034 Head of a Gang
    [PAT] A1030 Travel Plan
    [PAT] A1031 Hello World for U
    [PAT] A1029 Median
    [PAT] A1028 List Sorting
    [PAT] A1026 Table Tennis
  • 原文地址:https://www.cnblogs.com/HYZhou2018/p/12312913.html
Copyright © 2020-2023  润新知