Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
725 views
in Technique[技术] by (71.8m points)

请问微信小程序内H5页面回退如何刷新页面,或者说如何监听小程序回退按钮

比方说点击a页面的链接跳转到b页面,点击小程序左上角的回退,回到a页面时,刷新页面重新发起首页的接口请求


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

请问是在ios端吗?
如果是的话按下面操作试试
方式一:

var isPageHide = false; 
window.addEventListener('pageshow', function () { 
    if (isPageHide) { 
        window.location.reload(); 
    } 
}); 
window.addEventListener('pagehide', function () { 
    isPageHide = true; 
}); 

方式二:

window.onpageshow = function(event){
    //event.persisted 判断浏览器是否有缓存, 有为true, 没有为false
    if (event.persisted) {  
        window.location.reload();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...