Last active
October 17, 2024 04:20
-
-
Save ninan1028/77b4adac269a82e9ce3c5a7259439e71 to your computer and use it in GitHub Desktop.
移动端页面回退刷新
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
网址 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); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// 页面回退刷新 | |
var isPageHide = false; | |
window.addEventListener('pageshow', function () { | |
if (isPageHide) { | |
window.location.reload(); | |
} | |
}); | |
window.addEventListener('pagehide', function () { | |
isPageHide = true; | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
部分 小米 手机 原生 浏览器 不支持上面的 回退 刷新 需要 用 新 的 | |
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