Answers for "delete all cookies javascript"

1

javascript get all cookies

var getCookies = function(){
  var pairs = document.cookie.split(";");
  var cookies = {};
  for (var i=0; i<pairs.length; i++){
    var pair = pairs[i].split("=");
    cookies[(pair[0]+'').trim()] = unescape(pair.slice(1).join('='));
  }
  return cookies;
}

var myCookies = getCookies();
console.log(myCookies);
Posted by: Guest on March-07-2020
6

clear cookies js

function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}

deleteAllCookies();
Posted by: Guest on June-27-2020
5

javascript delete cookie

function deleteCookie(name) {
  document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
Posted by: Guest on May-20-2020
2

delete cookies by domain javascript

document.cookie = 'my_cookie=; path=/; domain=.example.com; expires=' + new Date(0).toUTCString();
Posted by: Guest on July-01-2020
1

clearing cookie in js

document.cookie.split(";")
  .forEach(function(c) { 
  	document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
Posted by: Guest on December-23-2020
0

delete all cookies javascript

function clearCookies(wildcardDomain=false, primaryDomain=true, path=null){
    pathSegment= path ? '; path=' + path : ''
    expSegment="=;expires=Thu, 01 Jan 1970 00:00:00 GMT"
    document.cookie.split(';').forEach(
        function(c) { 
            primaryDomain && (document.cookie = c.replace(/^ +/, "").replace(/=.*/, expSegment + pathSegment))
            wildcardDomain && (document.cookie = c.replace(/^ +/, "").replace(/=.*/, expSegment + pathSegment + '; domain=' + document.domain))
         }
     )
}
Posted by: Guest on June-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language