这里有个例子,你看看
[CODE]<html><head></head>
<body>
<script language="Javascript">
<!--
function getCookieVal(offset){
var endstr=document.cookie.indexOf(";",offset);
if(endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,endstr));
}
function FixCookieDate(date){
var base=new Date(0);
var skew=base.getTime();
if(skew>0)
base.setTime(base.getTime()-skew);
}
function GetCookie(name){
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while(i<clen){
var j=i+alen;
if(document.cookie.substring(i,j)==arg)
return getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if(i==0) break;
}
return null;
}
var expdate=new Date();
FixCookieDate(expdate);
expdate.setTime(expdate.getTime()+(5*60*1000));
countimg=(GetCookie("countimg")!=null)?(GetCookie("countimg")-1):-1;
countimg=(countimg<-1)?-1:countimg;
imgarray=new Array(4);
if(document.images){
imgarray[0]=new Image(205,56);
imgarray[1]=new Image(205,56);
imgarray[2]=new Image(205,56);
imgarray[3]=new Image(205,56);
}
else{
imgarray[0]="";
imgarray[1]="";
imgarray[2]="";
imgarray[3]="";
}
imgarray[0].src="http://bbs.bc-cn.net/UploadFace/147166.gif";
imgarray[0].URL="http://www.sohu.com";
imgarray[1].src="http://bbs.bc-cn.net/UploadFace/13383.gif";
imgarray[1].URL="http://www.yahoo.com";
imgarray[2].src="http://bbs.bc-cn.net/Images/userface/image1.jpg";
imgarray[2].URL="http://www.263.com";
imgarray[3].src="http://bbs.bc-cn.net/UploadFace/119148.gif";
imgarray[3].URL="http://www.chinaren.com";
function updateim(countimg){
return countimg;
}
function overhref2(){
updateim(countimg);
if(imgarray[countimg]!=null){
window.status=imgarray[countimg].URL;
return true;
}
}
function outhref2(){
window.status="";
return true;
}
function clickhref2(){
updateim(countimg);
if(imgarray[countimg]!=null){
window.location=imgarray[countimg].URL;
}
}
function showimage(){
countimg++;
if(document.images){
if(countimg>imgarray.length-1){
countimg=imgarray.length-imgarray.length;
}
document.images.banner.src=imgarray[countimg].src;
exbannerID=setTimeout("showimage()",1000);
}
}
function setit2(){
updateim(countimg);
document.cookie="countimg="+countimg+"; expires="+expdate.toGMTString();
}
function getit2(){
countimg=(GetCookie("countimg")!=null)?(GetCookie("countimg")):0;
updateim(countimg);
if(exbannerID!=null){
clearTimeout(exbannerID);
showimage();
}
}
function initCookies(){
window.onunload=setit2;
window.onfocus=getit2;
window.onblur=setit2;
}
function initBanner(){
showimage();
cookieID=setTimeout("initCookies()",1000);
}
window.onload=initBanner
//-->
</script>
<a onClick="clickhref2()" onMouseOver="overhref2();return true;" onMouseOut="outhref2();return true;"><img src="" name="banner" width="500" height="400" border="0"></a>
</body></html>[/CODE]