经常遇到一些页面跳转的问题,当我们用window.history.go()/window.history.back()/window.history.forward(),只能实现页面返回上一页,但是却无法刷新返回到的页面,所以,总结(解析)如下方法:(从a.html跳转到b.html)
<script>
function goback(){
window.history.go(-1);//正常返回,a.htm不刷新
window.history.back();//同上
window.history.forward();//同上
window.opener.location.reload();// 只有当该页面为新窗口时有效,即<a href="b.html" target="_blank">b.html</a>
window.opener.location.href = window.opener.location.href ;//同上
window.parent.location.reload();//框架页中有效
document.parentWindow.location.reload();//刷新的是自己
window.location.href ="a.htm"//不断刷新a.html
}
</script>
<body>
<A href="history.html" οnclick="javascript:location.replace(this.href);event.returnValue=false; ">方法一:返回上一页并刷新页面</A>
<a href="javascript:" οnclick="self.location=document.referrer;">方法二:返回上一页并刷新</a>
<a href="javascript:window.history.go(-1)">方法三:返回上一页,不刷新history.html</a>
<a href="javascript:document.parentWindow.location.reload()">方法四:返回上一页面刷新的是自己</a>
</body>