“Exclua todos os cookies javascript” Respostas de código

JavaScript Obtenha todos os 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);
Mobile Star

biscoitos claros 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();
Lokesh003Coding

JavaScript Excluir cookie

function deleteCookie(name) {
  document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
TC5550

Excluir cookies por javascript de domínio

document.cookie = 'my_cookie=; path=/; domain=.example.com; expires=' + new Date(0).toUTCString();
Yellowed Yak

JavaScript limpa todos os cookies

const clearCookies = document.cookie.split(';').forEach(cookie => document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date(0).toUTCString()};path=/`));
Rashid Siddique

Exclua todos os 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))
         }
     )
} 
Zealous Zebra

Respostas semelhantes a “Exclua todos os cookies javascript”

Perguntas semelhantes a “Exclua todos os cookies javascript”

Mais respostas relacionadas para “Exclua todos os cookies javascript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código