cookie应用

//alert("我在这");
//s首页判断是否有cookie决定弹窗
/***
* 设置Cookie (通用函数)
* cookieName Cookie 名称
* cookieValue Cookie 值
* nDays Cookie 过期天数
*/
function SetCookie(cookieName, cookieValue, nDays)
{
/* 当前日期 */
var today = new Date();

/* Cookie 过期时间 */
var expire = new Date();

/* 如果未设置nDays参数或者nDays为0,取默认值 1 */
if(nDays == null || nDays == 0) nDays = 1;

/* 计算Cookie过期时间 */
expire.setTime(today.getTime() + nDays * 24 * 60 * 60 * 1000); //获取毫秒数

/* 设置Cookie值 */
document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}

/*
* 读取指定的Cookie值
* cookieName Cookie名称
*/
function GetCookie(cookieName)
{
//alert("GetCookie");
/* Cookie 字符串 */
var theCookie = "" + document.cookie;

/* 找到cookieName的位置 */
var ind = theCookie.indexOf(cookieName);

/* 如果未找到cookieName,返回空字符串 */
if(ind == -1 || cookieName == "")
return "";

/* 确定分号的位置 */
var ind1 = theCookie.indexOf(';', ind);
if(ind1 == -1)
ind1 = theCookie.length;

/* 读取Cookie值 */
return unescape(theCookie.substring(ind+cookieName.length + 1, ind1));
}
//e首页判断是否有cookie决定弹窗


var ffusername = GetCookie("ffusername");

// 如果用户已经访问过
if(ffusername && ffusername.length >0)
{
//alert(ffusername)
}
else
{
// 设置cookie
//alert("我未访问过")
SetCookie("ffusername","feifeiuser",7);

$('#popupBoxAd').PopupDiv({
modal: true,
closeTitle: true,
close_btn: true,
minWidth: '983',
minHeight: '511'
});
}

posted @ 2013-06-26 22:06  Arz  阅读(148)  评论(0编辑  收藏  举报