可能会有兼容性问题 火狐下面应该是可以的,我自己测试通过<!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=gb2312" />
<title>无标题文档</title>
<style>
body{
font-size:12px;
}
.div{
position:relative;
top: 0;
left:50%;
display: block;
width: 240px;
padding:10px 0;
height:100px;
background: #fcb34c;
z-index: 1;
}
.div_x{
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #fcb34c;
position:absolute;
left:50%;
bottom:-10px;
margin-left:-5px;
}.div_close{
width:30px;
height:30px;
position:absolute;
right:2px;
top:2px;
background:#FFF;
cursor:pointer;
}</style>
<script type="text/javascript">
function Cookie(key,value)
{
this.key=key;
if(value!=null)
{
this.value=escape(value);
}
this.expiresTime=null;
this.domain=null;
this.path="/";
this.secure=null;
}
Cookie.prototype.setValue=function(value){this.value=escape(value);}
Cookie.prototype.getValue=function(){return (this.value);}Cookie.prototype.setExpiresTime=function(time){this.expiresTime=time;}
Cookie.prototype.getExpiresTime=function(){return this.expiresTime;}Cookie.prototype.setDomain=function(domain){this.domain=domain;}
Cookie.prototype.getDomain=function(){return this.domain;}Cookie.prototype.setPath=function(path){this.path=path;}
Cookie.prototype.getPath=function(){return this.path;}Cookie.prototype.Write=function(v)
{
if(v!=null)
{
this.setValue(v);
}
var ck=this.key+"="+this.value;
if(this.expiresTime!=null)
{
try
{
ck+=";expires="+this.expiresTime.toUTCString();;
}
catch(err)
{
alert("expiresTime参数错误");
}
}
if(this.domain!=null)
{
ck+=";domain="+this.domain;
}
if(this.path!=null)
{
ck+=";path="+this.path;
}
if(this.secure!=null)
{
ck+=";secure";
}
document.cookie=ck;
}
Cookie.prototype.Read=function()
{
try
{
var cks=document.cookie.split("; ");
var i=0;
for(i=0;i <cks.length;i++)
{
var ck=cks[i];
var fields=ck.split("=");
if(fields[0]==this.key)
{
this.value=fields[1];
return (this.value);
}
}
return null;
}
catch(err)
{
alert("cookie读取错误");
return null;
}
}
</script>
<script type="text/javascript" language="javascript">
window.onload=function(){
var ck=new Cookie("HasLoaded"); //每个页面的new Cookie名HasLoaded不能相同
if(ck.Read()==null){//未加载过,Cookie内容为空
alert("首次打开页面");
//设置保存时间
var dd = new Date();
dd = new Date(dd.getYear() + 1900, dd.getMonth(), dd.getDate());
dd.setDate(dd.getDate() + 365);
ck.setExpiresTime(dd); ck.Write("true"); //设置Cookie。只要IE不关闭,Cookie就一直存在
}
else{//Cookie存在,表示页面是被刷新的
alert("页面刷新");
document.getElementById('div').style.display = "none";
}
}
</script>
</head><body>
<div class="div" id="div">
<div class="div_close">
关闭
</div>
</div></body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
body{
font-size:12px;
}
.div{
position:relative;
top: 0;
left:50%;
display: block;
width: 240px;
padding:10px 0;
height:100px;
background: #fcb34c;
z-index: 1;
}
.div_x{
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #fcb34c;
position:absolute;
left:50%;
bottom:-10px;
margin-left:-5px;
}.div_close{
width:30px;
height:30px;
position:absolute;
right:2px;
top:2px;
background:#FFF;
cursor:pointer;
}</style>
<script type="text/javascript">
function Cookie(key,value)
{
this.key=key;
if(value!=null)
{
this.value=escape(value);
}
this.expiresTime=null;
this.domain=null;
this.path="/";
this.secure=null;
}
Cookie.prototype.setValue=function(value){this.value=escape(value);}
Cookie.prototype.getValue=function(){return (this.value);}Cookie.prototype.setExpiresTime=function(time){this.expiresTime=time;}
Cookie.prototype.getExpiresTime=function(){return this.expiresTime;}Cookie.prototype.setDomain=function(domain){this.domain=domain;}
Cookie.prototype.getDomain=function(){return this.domain;}Cookie.prototype.setPath=function(path){this.path=path;}
Cookie.prototype.getPath=function(){return this.path;}Cookie.prototype.Write=function(v)
{
if(v!=null)
{
this.setValue(v);
}
var ck=this.key+"="+this.value;
if(this.expiresTime!=null)
{
try
{
ck+=";expires="+this.expiresTime.toUTCString();;
}
catch(err)
{
alert("expiresTime参数错误");
}
}
if(this.domain!=null)
{
ck+=";domain="+this.domain;
}
if(this.path!=null)
{
ck+=";path="+this.path;
}
if(this.secure!=null)
{
ck+=";secure";
}
document.cookie=ck;
}
Cookie.prototype.Read=function()
{
try
{
var cks=document.cookie.split("; ");
var i=0;
for(i=0;i <cks.length;i++)
{
var ck=cks[i];
var fields=ck.split("=");
if(fields[0]==this.key)
{
this.value=fields[1];
return (this.value);
}
}
return null;
}
catch(err)
{
alert("cookie读取错误");
return null;
}
}
</script>
<script type="text/javascript" language="javascript">
window.onload=function(){
var ck=new Cookie("HasLoaded"); //每个页面的new Cookie名HasLoaded不能相同
if(ck.Read()==null){//未加载过,Cookie内容为空
alert("首次打开页面");
//设置保存时间
var dd = new Date();
dd = new Date(dd.getYear() + 1900, dd.getMonth(), dd.getDate());
dd.setDate(dd.getDate() + 365);
ck.setExpiresTime(dd); ck.Write("true"); //设置Cookie。只要IE不关闭,Cookie就一直存在
}
else{//Cookie存在,表示页面是被刷新的
alert("页面刷新");
document.getElementById('div').style.display = "none";
}
}
</script>
</head><body>
<div class="div" id="div">
<div class="div_close">
关闭
</div>
</div></body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货