[英]How to use preventBack() to refresh a page when pressing back button?
This code forwards if pressing back button in both iOS & Android: 如果同时在iOS和Android中按下返回按钮,则此代码将转发:
<script type = "text/javascript" >
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>
This code refreshes a page when hitting or swiping back in iOS but not working in android: 在iOS中点击或向后滑动时,此代码刷新页面,但在android中不起作用:
<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
var e=document.getElementById("refreshed");
if(e.value=="no")e.value="yes";
else{e.value="no";location.reload();}
}
</script>
So can we make a code that works in both iOS & android to refresh when hitting back or swiping back using preventBack() function. 因此,我们可以制作一个可以在iOS和android中使用的代码,以使用preventBack()函数回击或向后滑动时刷新的代码。 Is it possible?
可能吗?
Use the below code, this will helps you to stop click back and reload the page too. 使用下面的代码,这将帮助您停止单击并重新加载页面。
function preventBack() {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
location.reload();
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.