我想通过点击浏览器返回页面来刷新页面a [英] I want to refresh the page a when I comes to page a by clicking browser back bu
问题描述
大家好,
当我点击浏览器后退按钮进入页面A时,我想刷新页面A.
我正在使用
location.reload();
但是它无限清爽。如果我申请了一些条件,那么也会发生同样的事情。
有什么解决方案?
问候
Pawan
我尝试了什么:
location.reload();
用于某些条件,如检查bool是真的等。
Hi all,
I want to refresh the page A when I comes to Page A by clicking browser back button.
I'm using
location.reload();
but it is refreshing infinitely. If i apply some condition then also then also same thing is happening.
What is the solution?
Regards
Pawan
What I have tried:
location.reload();
used with some condition like checking bool is true etc.
推荐答案
看看这里: javascript - 通过浏览器返回按钮时重新加载网站 - Stack Overflow [ ^ ]
有很多方法可以实现你的目标。但最初的解决方案是
There are many ways to achieving your goal. But originally solution is
location.reload();
现在,我只是通过介绍一些使用location.reload的方法给你一个想法。
1: -
Now, i just give you an idea by present some ways to using location.reload.
1:-
//check index of reloading page and reload the page accordingly.
if (window.location.href.indexOf('reload')==-1) {
window.location.replace(window.location.href+'?reload');
}
2: -
2:-
if(window.top==window) {
// You're not in a frame, so you reload the site.
window.setTimeout('location.reload()', 5000); //Reloads after five seconds
}
else {
//You're inside a frame, so you stop reloading.
}
3: -
3:-
// You should keep a flag in cookie, server session, or local storage. For example:
window.onload = function () {
if (! localStorage.OnceLoad) {
localStorage.setItem("OnceLoad", "true");
window.location.reload();
}
}
这篇关于我想通过点击浏览器返回页面来刷新页面a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!