添加Cookie到Fancy Box Popup [英] Add Cookie to Fancy Box Popup
本文介绍了添加Cookie到Fancy Box Popup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个POPUP我可以使用弹出不断 - 我想添加一个7天的cookie吗?这是可能与我有什么吗?
I have this POPUP I can use to popup constantly - I wanted to add a 7 day cookie to it? Is that possible with what I have?
<script type="text/javascript">
jQuery(document).ready(function() {
$.fancybox(
'<h2>' + {{ settings.popup_title | json }} + '</h2><p>' + {{ settings.popup_content | json }} + '</p>',
{
'autoDimensions' : false,
'width' : 450,
'height' : 'auto',
'transitionIn' : 'none',
'transitionOut' : 'none'
}
);
});
</script>
推荐答案
基于这个答案,你可以用你喜欢的代码调整:
Based on this answer, you can tweak the code with what you have like :
function openFancybox() {
setTimeout(function () {
$.fancybox(
'<h2>' + {
{
settings.popup_title | json
}
} + '</h2 > < p > ' + {
{
settings.popup_content | json
}
} + ' < /p>', {
'autoDimensions': false,
'width': 450,
'height': 'auto',
'transitionIn': 'none',
'transitionOut': 'none'
});
}, 5000);
}
$(document).ready(function () {
var visited = $.cookie('visited');
if (visited == 'yes') {
return false;
} else {
openFancybox();
}
$.cookie('visited', 'yes', {
expires: 7
});
});
这将会在第一次访问5秒后触发fancybox 7天后,假设访问者尚未清除浏览器的缓存/ Cookie。
This will trigger fancybox after 5 seconds (or the time you prefer) on first visit only and during the following 7 days, assuming that the visitors haven't cleared their browser's cache/cookies.
确保您已正确加载 jQuery cookie插件,以及jQuery + fancybox js和css文件。
Make sure you have properly loaded the jQuery cookie plugin, as well as jQuery + fancybox js and css files.
这篇关于添加Cookie到Fancy Box Popup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文