JS添加和获取Cookie

JS添加和获取Cookie

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery设置浏览器缓存cookie提示内容显示隐藏</title>
<meta name="description" content="jquery制作通过判断各种浏览器版本等,来设置各个浏览器缓存cookie,控制模块内容或区域在浏览器缓存cookie的情况下,是否显示或隐藏等操作。" />
</head>
 
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    
    $('.WebDown .Close').click(function(){
        $('.WebDown').fadeOut(300); 
        if($("#NotShow").attr("checked")){
            setCookie("Browse","idea",'0');
        }
    });
    
    
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    
    
    if(getCookie("Browse")=="idea"){
        $('.WebDown').hide();
    }else{
        if(s){
            $('.WebDown').fadeIn(200);
        }
    }
 
});
 
function getCookie( name ){
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}
 
function setCookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}
</script>
 
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
/* WebDown */
.WebDown{width:220px;border:solid 1px #ffbb76;margin:30px auto;}
.WebDown .tipbox{position:relative;height:50px;background:#fffcef;padding:10px;font-size:12px;}
.WebDown .laba,.WebDown .Close,.WebDown .arrow{background:url(http://www.17sucai.com/preview/1/2013-05-02/cookie/images/tipboxbg.gif) no-repeat;}
.WebDown .laba{display:block;float:left;width:42px;height:39px;overflow:hidden;background-position:-27px 0;margin:5px 0 0 5px;}
.WebDown .tiptext{float:left;margin-left:15px;display:inline;}
.WebDown .tiptext h3{font-size:16px;color:#db7c22;font-family:"微软雅黑","宋体";height:34px;line-height:24px;}
.WebDown .tiptext p label{color:#999;cursor:pointer;margin-left:5px;}
.WebDown .Close{width:14px;height:14px;overflow:hidden;background-position:-13px 0px;position:absolute;bottom:10px;right:10px;cursor:pointer;}
.WebDown .arrow{display:block;width:13px;height:7px;overflow:hidden;background-position:0 -7px;position:absolute;left:15px;top:-7px;}
</style>
 
<div class="WebDown">
    <div class="tipbox">
        <span class="arrow"></span>
        <span class="laba"></span>
        <div class="tiptext">
            <h3>点击采集发布商品</h3>
            <p><input type="checkbox" id="NotShow" /><label for="NotShow">以后不再显示</label></p>
        </div>
        <div class="Close"></div>
    </div>
</div>
    
 
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值