2013-12-19 52 views
0

使用fancyBox v2和jQuery Cookie插件。每個會話在頁面加載時顯示fancybox

代碼:

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

它的工作原理。但我想,當我關閉網站或瀏覽器並返回時,再次顯示fancybox。試過,但不工作:

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

if(check_cookie == null){ 

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

通過DevTools經過,出現此錯誤:

Uncaught SyntaxError: Unexpected token) on 42. 

42. line: 

    }); 

我怎樣才能解決這個問題?

回答

1

規定的時限,以使用網站而分配,讓說,30分鐘

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

參考以下鏈接,裁判..

How to expire a cookie in 30 minutes using jQuery?

0

這是一個簡單的語法錯誤。 onComplete是fancybox的API選項,因此它進入了fancybox功能,如

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