24小时后删除localStorage

时间:2019-06-29 12:56:39

标签: javascript jquery

当一次显示特定元素时,我使用以下代码将其隐藏。但是我想扩展代码,以便将其隐藏仅24小时。

我该如何实现?

<script type="text/javascript">
     /* Check if all resource are loaded */
     $(window).load(function() {
        setTimeout(function() {
           $('#data-popup-box-container').fadeOut('fast');

           // Add entry in localstorage that Popup displayed once :)
           localStorage.setItem("popupDisplayed", "yes");
        }, 7000);
    });  

    /* On reload check if localstorage value is yes :) */
    $(document ).ready(function() {
        var popupDisplayed = localStorage.getItem("popupDisplayed");
        /* If local storage value is yes - remove element directly from dom */
        if(popupDisplayed && popupDisplayed == 'yes') {
           $('#data-popup-box-container').hide();
        } else {
           $('#data-popup-box-container').show();
        }
    });
</script>

0 个答案:

没有答案