我有一个JSP页面,即使在删除其中一个内容后也会显示以前的内容。我正在努力找到问题,但我需要快速解决这个问题。我在 JavaScript 中很弱,所以请帮帮我。我需要一个 JavaScript ,每次访问页面时都会自动重新加载页面。重新加载页面确实解决了问题。
答案 0 :(得分:7)
如果您只想做一次,我会使用localStorage
:
if (localStorage.getItem('loadedOnce') === 'true') {
// don't reload page, but clear localStorage value so it'll get reloaded next time
localStorage.removeItem('loadedOnce');
} else {
// set the flag and reload the page
localStorage.setItem('loadedOnce', 'true');
document.location.reload(true);
}
我真的建议调查为什么会这样做,而不是试图解决这个问题。
注意:强>
这在旧版浏览器中不起作用。有关详细信息,请参阅mdn's compatability table(但IE8确实支持它)。
答案 1 :(得分:1)
基于 @Omar 的回答,类似于 tjameson 。它只是使用cookie。
var int=self.setTimeout(function(){refresh()},1000);
function refresh() {
if (document.cookie.indexOf("reloaded") === -1){
document.cookie += ";reloaded";
document.location.reload(true);
}
else {
document.cookie = document.cookie.replace(/;reloaded/g, '');
}
}