我正在添加以下代码以添加叠加层
$(function () {
{
$('#overlay').fadeIn('fast', function () {
$('#overlaybox').animate({ 'top': '90px' }, 500);
//$('#box').css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
$('#overlaybox').css("left", (($(window).width() - $('#overlaybox').outerWidth()) / 2) + $(window).scrollLeft() + "px");
$('#nabshow').fadeOut('fast');
})
}
});
我发现以下代码可以根据 cookie 的可用性打开一个弹出窗口:
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;
}
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);
}
}
}
function showPopupOnce() {
var hasSeenPopup = myGetCookie("has_seen_popup");
if (hasSeenPopup === null || hasSeenPopup === ""){
// the user has never seen the popup, so show him!
window.open("http://mywebsite.com/popup.html", "myPopupWindow");
}
// either way, set the cookie so the user will never see the window again
mySetCookie("has_seen_popup", "true", 365); // 365 days = 1 year
}
<body onLoad="showPopupOnce();">
我需要在覆盖代码中进行哪些更改以确保它只显示一次。我将添加 get cookie 和 setcookie 函数,然后我该怎么办:
谢谢阿纳布