为什么本地存储在页面刷新后甚至不应该打开也不工作?

时间:2019-04-07 08:43:32

标签: javascript jquery local-storage

我正在使用它,但是cookie消息在每次刷新和打开选项卡后仍然出现。

 $(document).ready(function () {
    if (!!localStorage.getItem('firstVisitVisp')) {

        localStorage.setItem('firstVisitVisp', 'true');

        setTimeout(function () {
            $("#cookieConsent").fadeIn(200);
        }, 4000);

        $("#closeCookieConsent, .cookieConsentOK").click(function () {
            $("#cookieConsent").fadeOut(200);
        });
    }
});

1 个答案:

答案 0 :(得分:2)

您快到了-只需移除!!并将其更改为!

if (!localStorage.getItem('firstVisitVisp')) {...}
相关问题