RT,想在不关闭浏览器的情况下删除cookie,可是网上找了好多方法没有一个好使的,有没有大神指教一下啊?谢谢啦JavaScriptCookie
解决方案 »
- 调用google map怎么不能得到SubAdministrativeArea等的信息
- 有没有方法能让JS最后加载,以加快大页面的整体载入速度
- jQuery官网上的jQuery Starterkit 下载内容很怪?
- 请教一个判断日期是否合法的javascript
- 可不可以实现这样的功能
- 求教关于使图片循环隐藏和现实得简单问题?
- 在用一个页面中,怎么将一个列表中选择的选项传递到另外一个列表中?
- 如何在一个页面中不需警告的关闭该页面
- 是否可以通过一个函数动态替换html代码,然后动态更新啊???急!!在线等待!!
- javascript 小问题,如何对普通文字实现和链接一样的视觉效果?
- 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