kuldarim
kuldarim

Reputation: 1106

Cookie does not work in safari

I have written a simple div, which hides when user clicks (X) button. And does not appear next time when user gets back to the website if he has closed the div before. All this logic is stored using cookies. And works perfect in chrome and firefox but not in safari.

My javascript code to store cookie info:

$( document ).ready(function() {
    var cookie = document.cookie;
    if (cookie.indexOf('subscription=', 0) !== -1) {
        $('#pushDown').css('display', 'none');
    } else {
        $("#pushDown").slideDown("slow");
    }
    $("#close").click(function(){
        var cookie = document.cookie;
        var expiration = new Date();
        expiration.setDate(expiration.getDate()+1);
        document.cookie = 'subscription=1;expires=' + expiration + ';path=/';
        $("#pushDown").slideUp("slow");
    });
});

NOTE: to simulate browser refresh click run several times. jsFiddle link

Maybe someone know there the problem cood be?

Upvotes: 0

Views: 7190

Answers (1)

epascarello
epascarello

Reputation: 207501

Change

'subscription=1;expires=' + expiration + ';path=/';

to

'subscription=1;expires=' + expiration.toGMTString() + ';path=/';

Upvotes: 2

Related Questions