RT,想在不关闭浏览器的情况下删除cookie,可是网上找了好多方法没有一个好使的,有没有大神指教一下啊?谢谢啦JavaScriptCookie
解决方案 »
- jquery datepicker不同浏览器,不中版本验证问题
- 关于FireFox下document.activeElement问题
- 一个JS检测网页窗口的高宽代码修改
- 显示层坐标问题,高手帮忙~~~~
- jquery table问题
- 探秘JavaScript框架
- 高手来帮忙啦,如何点删除后把后面的文本框的值传到前面去,或者将后面的删除按钮的值重写??
- 怎么样在鼠标按下时开始执行一段循环,放开时则循环结束?大侠帮忙啊!
- 想学习javascript,请帮忙推荐一本书!!
- 请问哪位可以提供客户端动态调整表格宽度的JS或VBS源代码
- js实现打开浏览文件窗口
- 我想把javascript里的一个数组变量的值提交到一个servlet,请问怎么做
delCookie
http://www.cnblogs.com/cuihongyu3503319/archive/2008/04/18/1160084.html
为什么会没有效果?function delCookie(name)
{
document.cookie = name + "=0;expires=" +
(new Date(((new Date()).getTime() - 1))).toGMTString();
}比如这个简单的删除cookie,应该只要设置过期时间早于当前时间不就可以了?
上面的代码IE9,Maxthon4,Chrome27均测试有效啊。
至于浏览器删不删那不是你的事吧,它不删那也没得办法吧。。
//example $.cookie(’name’, ‘value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
}
$.cookie(’name’, null)就是删除COOKIE