Skip to content

Instantly share code, notes, and snippets.

@ninan1028
Last active November 15, 2019 07:12
Show Gist options
  • Save ninan1028/77b4adac269a82e9ce3c5a7259439e71 to your computer and use it in GitHub Desktop.
Save ninan1028/77b4adac269a82e9ce3c5a7259439e71 to your computer and use it in GitHub Desktop.
移动端页面回退刷新
网址 http://blog.weiqinxue.cn/blogs/index.php/User/articleview/ArticleID/U2A155
if(Q.ua.IOS){
Q.$(window).on("pagehide",function(){
var $body = $(document.body);
$body.children().remove(); // wait for this callback to finish executing and then...
setTimeout(function() {
$body.append("<script type='text/javascript'>window.location.reload(true);</script>");
});
});
}
//for android qq browser
Q.$(window).on('pageshow', function(evt){
setTimeout(function(){
if(evt.persisted){
location.reload(true);
}
});
});
<script>
// 页面回退刷新
var isPageHide = false;
    window.addEventListener('pageshow', function () {
      if (isPageHide) {
        window.location.reload();
      }
    });
    window.addEventListener('pagehide', function () {
      isPageHide = true;
    });
</script>
部分 小米 手机 原生 浏览器 不支持上面的 回退 刷新 需要 用 新 的
api
引入
http://www.zhangxinxu.com/wordpress/2012/11/page-visibility-api-introduction-extend/ 中的 库
<script>
/***解决 小米 vivo 自带浏览器 回退不刷新问题***/
pageVisibility.visibilitychange(function(){
if((!pageVisibility.hidden)&&(!iswx)){
window.location.reload();
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment