问题描述
我有一个JSP页面,即使删除了其中一个内容,该页面仍显示先前的内容.我正在努力寻找问题,但我需要对此进行快速修复.我在 JavaScript 方面很弱,所以请帮帮我.我需要一个 JavaScript ,它将在每次访问该页面时自动重新加载该页面.重新加载页面确实可以解决问题.
I have a JSP page that is showing previous content even after deleting one of the content. I am working to find the problem but I need a quick fix for this. I'm weak in JavaScript so please help me out. I need a JavaScript that would reload the page automatically every time the page is visited. Reloading the page does solve the problem.
推荐答案
如果只想做一次,我会使用localStorage
:
If you want to do it just once, I would use 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);
}
我真的建议您调查一下为什么它会损坏,而不是试图解决问题.
I would really recommend looking into why this is broken, instead of trying to hack around the problem.
注意:
这不适用于较旧的浏览器.有关更多信息,请参见 mdn的兼容性表(IE8确实支持该表).
This doesn't work in older browsers. See mdn's compatability table for more information (IE8 does support it however).
这篇关于如何在每次加载页面时仅重新加载一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!