用Cookies判断用户首次登录

<script type="text/javascript">
$(document).ready(function() {
var newVisitor = isNewVisitor();// 如果是新访客
if(newVisitor === true)
{
// 动画弹出消息框
alert('您是新用户!');

   // 标记:已经向该访客弹出过消息。30天之内不要再弹
   setCookie("gznotes-visited","true", 5);
   }
 });

 function isNewVisitor() {
 // 从cookie读取“已经向访客提示过消息”的标志位
   var flg = getCookie("gznotes-visited");
    if (flg === "") {
    return true;
    } else {
     return false;
    }
 }

// 写cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays2460601000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires +";path=/";
}
// 读cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
</script>

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复