我想要找到如何設置JavaScript cookie,以便在瀏覽第4頁的瀏覽量之後顯示fancybox彈出窗口。JS cookie用於在第x頁面瀏覽後顯示內容
這裏是我使用的顯示的fancybox彈出的代碼,但你可以看到,這顯示只在第一次網頁瀏覽的代碼,它每天
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value + ";domain=.mysite.net;path=/";
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
jQuery(document).ready(function() {
var show = getCookie("fancyreg");
if(show==null || show=="") {
$.fancybox(
{
'type' : 'iframe',
'href' : 'http://www.mysite.net/popup/', //URL to popup page or image
'autoDimensions' : false,
'width' : 480,
'height' : 260,
'transitionIn' : 'none',
'transitionOut' : 'none'
}
);
setCookie('fancyreg','1',1);
}
});
我也想,如果到期後您可以幫助我如何在現有代碼中添加延遲,以便在3秒(3000毫秒)後彈出顯示。
我試着用的setTimeout(函數(),如下
<script type="text/javascript">
jQuery(document).ready(function() {
setTimeout(function() {
$.fancybox({
'type' : 'iframe',
'href' : 'http://www.mysite.net/popup/', //URL to popup page or image
'autoDimensions' : false,
'width' : 480,
'height' : 260,
'transitionIn' : 'none',
'transitionOut' : 'none'
})
}, 4000);
});
</script>
,但它不能正常工作。
至於控制瀏覽量,我不知道如何設置,也沒有我能找到的任何資源幫助我通過這個。
非常感謝
我們不是代碼猴子。你有什麼嘗試? –
嗨,Jan,我通過使用setTimeout JS函數添加了彈出延遲的代碼。 – valdroni
您可能需要使用jQuery cookie插件。查看http://stackoverflow.com/a/8305703/1055987獲取更多信息。您可以在4天內設置cookie過期,然後打開fancybox – JFK