0

Using fancyBox v2 and jQuery Cookie plugins.

Code:

var check_cookie = $.cookie('the_cookie');
if(check_cookie == null){
$.cookie('the_cookie', 'the_value');
$("#hidden_link").fancybox().trigger('click');
}

It works. But I want, when I close site or browser and come back, display fancybox again. Tried this but not working:

var check_cookie = $.cookie('the_cookie');

if(check_cookie == null){

$("#hidden_link").fancybox().trigger('click'), {
'onComplete' : function() {
$.cookie('the_cookie', 'the_value');
}
});
}

Checked via DevTools, get this error:

Uncaught SyntaxError: Unexpected token ) on 42. 

42. line:

    });

How can I fix it?

JFK
  • 40,963
  • 31
  • 133
  • 306
user3099199
  • 49
  • 1
  • 8

2 Answers2

1

set time frame to cookie while assigning, lets say for 30 mins

var check_cookie = $.cookie('the_cookie');
if(check_cookie == null){
$.cookie('the_cookie', 'the_value', { expires: 30 * 60 * 1000 });
$("#hidden_link").fancybox().trigger('click');
}

refer below link for ref..

How to expire a cookie in 30 minutes using jQuery?

Community
  • 1
  • 1
0

It's a simple syntax error. onComplete is an API option of fancybox, therefore it goes inside the fancybox function like

var check_cookie = $.cookie('the_cookie');
if (check_cookie == null) {
    $("#hidden_link").fancybox({
        'onComplete': function () {
            $.cookie('the_cookie', 'the_value');
        }
    }).trigger('click');
}
JFK
  • 40,963
  • 31
  • 133
  • 306