can anyone please tell me what is the error on this code? I am trying to set a cookie for the fancybox popup but it is showing on every refresh. All .js are included.
<script>
$(document).ready(function(){
if(!$.cookie('the_cookie1')){
$.cookie('the_cookie1', 'true', { expires: 3});
$.fancybox(
'<h2>Hi!</h2><p>Lorem ipsum dolor</p>',
{
'autoDimensions' : false,
'width' : 350,
'height' : 'auto',
开发者_Python百科 'transitionIn' : 'none',
'transitionOut' : 'none'
}
);
}
});
</script>
I modified the code block to the following and it's functioning as expected both in Chrome 13 and FF5.
<script>
$(document).ready(function () {
var cookieName = 'the_cookie1';
var cookie = $.cookie(cookieName);
if(cookie === null) {
var cookieOptions = { expires: 3, path: '/' /*domain:, secure: false */ };
$.cookie(cookieName, 'true', cookieOptions);
$.fancybox(
'<h2>Hi!</h2><p>Lorem ipsum dolor</p>',
{
'autoDimensions': false,
'width': 350,
'height': 'auto',
'transitionIn': 'none',
'transitionOut': 'none'
}
);
}
});
</script>
FireFox 5
Chrome 13
First run, I receive the box and the cookie is set. Thereafter, no box.
I did notice some strangeness with Chrome where the cookie would not appear in the console occasionally but debugging the script in fact revealed the cookie was set and functioning.
try changing your condition to this:
if(! ($.cookie('the_cookie1')){...
this both covers null and 'undefined'.
精彩评论