Home > Web Front-end > JS Tutorial > JS method to clear specified cookies_javascript skills

JS method to clear specified cookies_javascript skills

WBOY
Release: 2016-05-16 16:35:58
Original
1612 people have browsed it

The example in this article describes the JS method of clearing specified cookies, which is very practical. Share it with everyone for your reference.

The specific implementation code is as follows:

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");
}

Copy after login

I hope this article will be helpful to everyone’s learning of js WEB front-end programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template