如何在页面加载时重新加载页面(相当于按下F5)
$( window ).load(function() {
window.location.reload(true);
});
Run Code Online (Sandbox Code Playgroud)
这循环自己.我怎么能只让它发生一次?
Ree*_*eno 13
这样做:
if (window.location.href.indexOf('reload')==-1) {
window.location.replace(window.location.href+'?reload');
}
Run Code Online (Sandbox Code Playgroud)
使用您的jQuery代码:
$( window ).load(function() {
if (window.location.href.indexOf('reload')==-1) {
window.location.replace(window.location.href+'?reload');
}
});
Run Code Online (Sandbox Code Playgroud)
小智 11
现在...... HTML5提供localStorage:
/* if my "reload" var isn't set locally.. getItem will be false */
if (!localStorage.getItem("reload")) {
/* set reload to true and then reload the page */
localStorage.setItem("reload", "true");
location.reload();
}
/* after reloading remove "reload" from localStorage */
else {
localStorage.removeItem("reload");
// localStorage.clear(); // or clear it, instead
}
Run Code Online (Sandbox Code Playgroud)
这不需要jquery,希望它有所帮助,因为它帮助了我
| 归档时间: |
|
| 查看次数: |
38068 次 |
| 最近记录: |