问题描述
这段代码不能实现啊............求解!!!functionaddCookie(objName,objValue,objHours){varstr=objName+"="+escape(objValue);if(objHours>0){//等于0时,关闭浏览器自动清除Cookies.vardate=newDate();varms=objHours*3600*1000;date.setTime(date.getTime()+ms);str+=";expires="+date.toGMTString();}document.cookie=str;}
解决方案
解决方案二:
cookie.jsvarCookies={};//设置Cookies。Cookies.setValue=function(name,value){varargv=arguments;varargc=arguments.length;varexpires=(argc>2)?argv[2]:null;varpath=(argc>3)?argv[3]:'/';vardomain=(argc>4)?argv[4]:null;varsecure=(argc>5)?argv[5]:false;document.cookie=name+"="+escape(value)+((expires==null)?"":(";expires="+expires.toGMTString()))+((path==null)?"":(";path="+path))+((domain==null)?"":(";domain="+domain))+((secure==true)?";secure":"");};//读取Cookies。Cookies.getValue=function(name){vararg=name+"=";varalen=arg.length;varclen=document.cookie.length;vari=0;varj=0;while(i<clen){j=i+alen;if(document.cookie.substring(i,j)==arg)returnCookies.getCookieVal(j);i=document.cookie.indexOf("",i)+1;if(i==0)break;}returnnull;};//清除Cookies。Cookies.clear=function(name){if(Cookies.getValue(name)){varexpdate=newDate();expdate.setTime(expdate.getTime()-(86400*1000*1));Cookies.setValue(name,"",expdate);}};//获取Cookies值。Cookies.getCookieVal=function(offset){varendstr=document.cookie.indexOf(";",offset);if(endstr==-1){endstr=document.cookie.length;}returnunescape(document.cookie.substring(offset,endstr));};
解决方案三:
指定会话型的cookie不就可以直接达到你的要求了吗??
解决方案四:
引用1楼zhuankeshumo的回复:
cookie.jsvarCookies={};//设置Cookies。Cookies.setValue=function(name,value){varargv=arguments;varargc=arguments.length;varexpires=(argc>2)?argv[2]:null;varpath=(argc>3)?argv[3]:'/';vardomain=(argc>4)?argv[4]:null;varsecure=(argc>5)?argv[5]:false;document.cookie=name+"="+escape(value)+((expires==null)?"":(";expires="+expires.toGMTString()))+((path==null)?"":(";path="+path))+((domain==null)?"":(";domain="+domain))+((secure==true)?";secure":"");};//读取Cookies。Cookies.getValue=function(name){vararg=name+"=";varalen=arg.length;varclen=document.cookie.length;vari=0;varj=0;while(i<clen){j=i+alen;if(document.cookie.substring(i,j)==arg)returnCookies.getCookieVal(j);i=document.cookie.indexOf("",i)+1;if(i==0)break;}returnnull;};//清除Cookies。Cookies.clear=function(name){if(Cookies.getValue(name)){varexpdate=newDate();expdate.setTime(expdate.getTime()-(86400*1000*1));Cookies.setValue(name,"",expdate);}};//获取Cookies值。Cookies.getCookieVal=function(offset){varendstr=document.cookie.indexOf(";",offset);if(endstr==-1){endstr=document.cookie.length;}returnunescape(document.cookie.substring(offset,endstr));};
这个不用调用么?直接导入文件就行了么?
解决方案五:
你关闭浏览器你都获取不到(IE除外)你还想清除本地文件个人目测不可以.
解决方案六:
不要设置cookie过期时间这样即为session模式关闭就自动匿了
解决方案七:
解决方案八:
不要设置cookie过期时间