【发布时间】:2016-01-12 03:20:17
【问题描述】:
我将这段代码 javascript 与 localStorage 一起使用(类似于 php 中的会话)
<script>
$(function(){
var a = localStorage.getItem('login');
if(a=="" || a==null){window.location.href = "dash-home.html";}
else{window.location.href = "dash-chat.html";}
});
</script>
但是当定位在 dash-home.html 中时,该页面总是刷新页面(F5 重复)
【问题讨论】:
-
重定向到dash-home时,表示用户已登录。如果是,则需要在localStorage中设置
login值。 -
设置
window.location.href时,页面会刷新。 -
我已经完成了,我问'重定向 dash-home 时总是刷新?' @Tushar
-
确保您的“脚本”在您的“dash-home.html”中不可用,因为它是您的中立地。
-
那么,我用什么? @fauxserious
标签: javascript jquery html local-storage