下面是我用来使广告每天展示一次的代码。我想将其切换为每5分钟显示一次。我以为将脚本中的1的值更改为0.004(如果1 =一天,.004 =大约5分钟),但它似乎无法正常工作。有人有什么想法吗?谢谢!

<style>
    #donationad {
        position: fixed;
        bottom: 0;
        left: 40px;
        width: 250px;
        height: 150px;
        z-index: 999;
        display: none;
    }

    #donationad.hide {
        display: none;
    }

    .closebutton {
        position: relative;
        top: 20px;
        left: 230px;
        cursor: pointer;
    }

    .closebutton img {
        width: 30px;
        height: auto;
        opacity: 1.0;
    }
</style>
<script type="text/javascript">
    $(document).ready(function() {
        $('.closebutton').click(function() {
            $("#donationad").toggleClass("hide");
        });
    });
</script>
<div id="donationad">
    <div class="closebutton"> <img src="http://www.dbknews.com/pb/resources/assets/img/modal_close_button.png"> </div>
    <a href="http://dbknews.com/donate"> <img src="https://s3.amazonaws.com/wapopartners.com/dbknews-wp/wp-content/uploads/2016/12/24020402/DBK-Donate250x150.jpg"> </a>
</div>
<script type="text/javascript">
    var cookie = document.cookie;
    if (cookie.indexOf('visited=', 0) == -1) {
        var expiration = new Date();
        expiration.setDate(expiration.getDate() + 1);
        document.cookie = 'visited=1;expires=' + expiration + ';path=/';
        var element = document.getElementById('donationad');
        element.style.display = 'block';
    }
</script>

最佳答案

Date.setDate设置月份中的日期,而不是“日期”。令人困惑?是。

您想要的是完全不同的东西。

document.cookie = 'visited=1;max-age=300;path=/';
// 300 is 5 minutes in seconds


这将创建一个只能使用5分钟的cookie,而您根本不需要处理日期。您将丢失旧版本的IE,它将把cookie视为临时版本。

10-05 20:54
查看更多