JS实现清除指定cookies的方法

本文实例讲述了JS实现清除指定cookies的方法,非常实用。分享给大家供大家参考。

具体实现代码如下:

function GetCookieValue(name) {
  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]);
   //PYYH=USERNAME=steven&PASSWORD=111111&UserID=1&UserType=1
   if (cookie.substring(0, name.length + 1) == (name + '=')) {
 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 //USERNAME=steven&PASSWORD=111111&UserID=1&UserType=1
 break;
   }
 }
  }
  return cookieValue;
}
function DelCookie(name) {
  var exp = new Date();
  exp.setTime(exp.getTime() + (-1 * 24 * 60 * 60 * 1000));
  var cval = GetCookieValue(name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function exit() {
  DelCookie("PYYH");
  window.location.replace("http://localhost:7877/index.aspx");
}

希望本文所述对大家js WEB前端程序设计的学习有所帮助。

若文章对您有帮助,帮忙点个赞!

0
-3
发布时间 2014-09-20 11:00:06
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)