문제

We built a notification with fancybox that needs to be shown to all of our users once but currently it's showing once on every page of the site and setting a cookie for every page the visitor visits, our code is as follows:

// jQuery Cookie popup
$(function() {
    if ($.cookie('cd-notification-cookie')) {
        // it hasn't been three days yet
    } else {
        $.fancybox.open([
            {
                href : '#notification'
            } 
        ], {
            maxWidth    : 420,
            maxHeight   : 800,
            fitToView   : false,
            width       : '90%',
            height      : 'auto',
            autoSize    : false,
            closeClick  : false,
            closeEffect : 'none'   
        });
      // set cookie to expire in 3 days
      $.cookie('cd-notification-cookie', 'true', { expires: 3});
    }
});

Is it possible to set a global cookie for the whole website instead of a per page basis?

도움이 되었습니까?

해결책

You can try to set the path to the base of the application like

$.cookie('cd-notification-cookie', 'true', { expires: 3, path: '/'});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top