1、简单的删除cookie
//删除cookiefunction deleteCookie(name){
var date=new Date()
date.setTime(date.getTime()-10000)
document.cookie=name+"=v expires="+date.toGMTString()
}
2、设置访问路径的cookie删除
/*** js 删除 http cookie
* @param name 名字
* @param path 路径
* @param domain 域名
*/
function deleteCookie(name,path,domain){
if(getCookie(name)) document.cookie= name+'='+
((path)?'path='+path:'')+
((domain)?'domain='+domain:'') +
'expires=Thu,01-Jan-1970 00:00:01 GMT'
}
/**
* js取得http cookie
* @param name cookie名字
*/
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 ) )
}
document.cookie = "xxx=yyy"// cookie 的删除
// 就是把一个键值对设置成过去的时间
document.cookie = "xxx=zzzexpires=" + date1date表示日期,表示cookie多久之后自动消失