Javascript 本地。如果为false,则重定向存储

Javascript 本地。如果为false,则重定向存储,javascript,html,redirect,local-storage,Javascript,Html,Redirect,Local Storage,我有一个像cookie一样需要验证的站点。但我想使用本地存储,因为它是一个移动概念。 我知道该项是通过测试设置的,但当它不正确时,我无法使页面重定向 <script language="javascript"> if (localStorage.getItem('itemVerified') = 'True') { window.location = "success.html"; } else { alert("You are not able to enter this sit

我有一个像cookie一样需要验证的站点。但我想使用本地存储,因为它是一个移动概念。 我知道该项是通过测试设置的,但当它不正确时,我无法使页面重定向

<script language="javascript">
 if (localStorage.getItem('itemVerified') = 'True') {
window.location = "success.html";
}
else {
alert("You are not able to enter this site!");
window.location = "error.html";
}
</script>

if(localStorage.getItem('itemVerified')='True'){
window.location=“success.html”;
}
否则{
警报(“您无法进入此网站!”);
window.location=“error.html”;
}

可能有两个错误,第一个错误是比较字符串缺少=符号:

不正确:
if(localStorage.getItem('itemVerified')='True'){

正确:
if(localStorage.getItem('itemVerified')=='True'){

第二种情况是,如果您要查看要从中加载文档的站点,则需要将操作添加到事件侦听器中,您可以执行以下操作。

    <script type="text/javascript">
     var verifyCookie = function(){

   if (localStorage.getItem('itemVerified') == 'True') {
    console.log("All right");
        window.location = "success.html";
   }
   else {
    alert("You are not able to enter this site!");
    window.location = "error.html";
   }
      };
     window.addEventListener ('DOMContentLoaded', verifyCookie, false);
    </script>

var verifyCookie=函数(){
if(localStorage.getItem('itemVerified')=='True'){
控制台日志(“好的”);
window.location=“success.html”;
}
否则{
警报(“您无法进入此网站!”);
window.location=“error.html”;
}
};
window.addEventListener('DOMContentLoaded',verifyCookie,false);

问候。

你有
=
而不是
=
,这是一个JS错误,所以我不知道这会如何重定向。无论你看它多少次,你都看不到明显的错误