Have div display ONLY on first time visit (cookies?)

前端 未结 1 1731
太阳男子
太阳男子 2020-12-19 14:18

I\'m trying to have a div display on the very first time a user visits my site. I\'m pretty sure I do this by using cookies, which I have limited experience with and am have

相关标签:
1条回答
  • 2020-12-19 15:01

    Your cookie code looks fine. You need to run it in the document ready handler, so that it waits until the document is loaded before toggling the DIV:

    $(function() {
        var visit=GetCookie("COOKIE1");
    
        if (visit==null){
            popbox3();
        }
        var expire=new Date();
        expire=new Date(expire.getTime()+7776000000);
        document.cookie="COOKIE1=here; expires="+expire;
    }
    

    I've also made setting the cookie unconditional, so that every visit to the site will push back the expiration time.

    0 讨论(0)
提交回复
热议问题