zoukankan      html  css  js  c++  java
  • H5 history.pushState 在微信内修改url后点击用safari打开/复制链接是修改之前的页面

    解决方案:url参数增加随机参数

    function wxRefresh() {
        var replaceQueryParam = (param, newval, search) => {
            var regex = new RegExp('([?;&])' + param + '[^&;]*[;&]?');
            var query = search.replace(regex, '$1').replace(/&$/, '');
    
            return (query.length > 2 ? query + '&' : '?') + (newval ? param + '=' + newval : '');
        };
    
        window.location.replace(location.protocol +
            '//' +
            location.host +
            location.pathname +
            replaceQueryParam('_wxr_', new Date().getTime(), location.search) +
            location.hash);
    };
    // 执行
    wxRefresh();




    优化加入refresh,避免重复刷新
    share(route) {
        var replaceQueryParam = (param, newval, search) => {
          var regex = new RegExp('([?;&])' + param + '[^&;]*[;&]?')
          var query = search.replace(regex, '$1').replace(/&$/, '')
          return (
            (query.length > 2 ? query + '&' : '?') +
            (newval ? param + '=' + newval : '')
          )
        }
    
        if (!route.query.refresh) {
          var chat = '&'
          if (!Object.keys(route.query).length) {
            chat = '?'
          }
          window.location.replace(
            location.protocol +
            '//' +
            location.host +
            location.pathname +
            replaceQueryParam('_wxr_', new Date().getTime(), location.search) +
            location.hash +
            chat + 'refresh=true'
          )
        }
      }
  • 相关阅读:
    js图片放大
    js编写点名器
    javascript中的math和随机数
    python中 __slots__
    python中 @property
    CentOS 6.5通过yum安装 MySQL-5.5
    linux下环境搭建
    oracle:ORA-01940无法删除当前已连接用户的解决方案
    不同版本apache(免安装)下部署Javaee多套项目
    使用poi处理excel
  • 原文地址:https://www.cnblogs.com/richard1015/p/8477869.html
Copyright © 2011-2022 走看看