mdnash
mdnash

Reputation: 81

Set an expiration date (and time) for a pop up that has a cookie

What can I add to the following that will prevent the pop up from loading after 8pm on New Years Eve?

$(document).ready(function(){
    // Start Cookie for PopUp
    if (document.cookie.indexOf('colorframe=true') === -1) {
    var expires = new Date();
    expires.setDate(expires.getDate()+1);
    document.cookie = "colorframe=true; escKey=true; expires="+expires.toUTCString();

        // Start Popup
        setTimeout(function () {
            $.colorbox({
                escKey: true,
                html: '<a href="---"><img src="---" width="550" height="550" alt="New Years Eve at ---"/></a>'
            });
        }, 2000);
    };
});

Upvotes: 1

Views: 1172

Answers (1)

yts
yts

Reputation: 1890

You could compare the current timestamp with the timestamp for 8pm. Using http://www.epochconverter.com/ I believe this is 1483232400000.

$(document).ready(function(){
    // Start Cookie for PopUp
    if ((new Date).getTime() > 1483232400000) return;

    //remainder of code here

});

This is assuming you trust your clients' computers time.

Upvotes: 2

Related Questions