解决方法来自:
https://blog.csdn.net/hbts_901111zb/article/details/76691900#commentBox
最近项目中在做一个功能,在app中内嵌h5页面做活动,活动页面1中有倒计时,当从页面1跳转到页面2后,再从页面2返回页面1的时候,在安卓下倒计时正常执行,在iOS下倒计时没有正确执行,原因是iOS离开页面1的时候,停止了js的定时器setInterval,并且返回页面1的时候没有重新加载页面1,导致页面1上的倒计时是接在之前离开页面1时继续下去的。
网上搜索解决方案:
1.在html代码中添加了以下代码没有作用
<meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-control" content="no-store"> <meta http-equiv="Expires" content="0">
2.在jsp的head中添加
<% response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", -1); %>
安卓下返回页面1会重新请求,iOS下不会重新请求
3.添加页面显示和隐藏事件
var isPageHide = false; window.addEventListener('pageshow', function () { if (isPageHide) { window.location.reload(); } }); window.addEventListener('pagehide', function () { isPageHide = true; });使用该方案解决了问题,从页面2返回页面1后自动刷新当前页面,安卓和iOS下都正常执行