如何在页面重新加载时返回上一页



当用户单击浏览器上的重新加载按钮时,如何返回上一页?尝试在created((中使用window.addEventListener("beforeunload",function(event(,但它显示了一条我不想显示的警报消息。

window.addEventListener("beforeunload", function(event) {
event.returnValue = "Write something";
window.history.go(-1);
});

如果您设置了一个cookie并在其中放入一个值,例如

hasopened = true 

然后当你的页面打开时,你可以阅读cookie并采取相应的行动。

<script>
window.addEventListener("load", afterLoaded,false);
function afterLoaded(){  <!-- below are just samples -->
<!-- alert("after load");  ---> 
<!-- lookForCityChange(); -->
<!--    over here you'd want to read the cookie. -->
}

function lookForCityChange() <!-- want to click the button -->
{   
<!-- window.location.replace('audiorecover.html');  --->
<!--   document.getElementById("ASongx").click(); -->
<!--    alert("Document...");     -->
}          
</script>

最新更新