<!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>
setcookie(name,value,expire,path,domain,secure)
参数
|
说明​
|
name
|
必需。规定 cookie 的名称。
|
value
|
必需。规定 cookie 的值。
|
expire
|
可选。规定 cookie 的有效期。
|
path
|
可选。规定 cookie 的服务器路径。
|
domain
|
可选。规定 cookie 的域名。
|
secure
|
可选。规定是否通过安全的 HTTPS 连接来传输 cookie。
|
360浏览器,也就是谷歌内核在6.3版本 次效果无效,在火狐和其他浏览器设置有效, 或者用http:协议里访问有效
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script>
var CookieUtil = {
get: function (name) {
var cookieName = encodeURIComponent(name) + "=",
cookieStart = document.cookie.indexOf(cookieName),
cookieValue = null;
if (cookieStart > -1) {
var cookieEnd = document.cookie.indexOf(";", cookieStart)
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}
cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
}
return cookieValue;
},
set: function (name, value, mins, path, domain, secure) {
var cookieText = encodeURIComponent(name) + "=" +encodeURIComponent(value);
var date = new Date();
date.setTime(date.getTime() + (mins * 60 * 1000));
if (date instanceof Date) {
cookieText += "; expires=" + date.toGMTString();
}
if (path) {
cookieText += "; path=" + path;
}
if (domain) {
cookieText += "; domain=" + domain;
}
if (secure) {
cookieText == "; secure";
}
document.cookie = cookieText;
},
unset: function (name, path, domain, secure) {
this.set(name, "", new Date(0), path, domain, secure);
}
};
var s22=new Date('2014/7/7 23:00:00').getTime();
var s2230=new Date().getTime();
var s23=new Date('2014/7/8 23:10:00').getTime();
CookieUtil.set('name','true',0.1);
//alert(s2230 >= s22 && s2230<=s23 )
function run(){
if( s2230 >= s22 && s2230<=s23){
if(CookieUtil.get('name')=='true'){
console.log("还没过期");
}else{
console.log("已经过期");
}
}
}
// //
setInterval(run,1000)
//
//
//
</script>
</head>
<body>
</body>
</html>