“Hapus semua cookie javascript” Kode Jawaban

JavaScript Dapatkan semua cookie

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

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

JavaScript Hapus Cookie

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

Hapus cookie dengan domain javascript

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

JavaScript Bersihkan semua cookie

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

Hapus semua cookie 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

Jawaban yang mirip dengan “Hapus semua cookie javascript”

Pertanyaan yang mirip dengan “Hapus semua cookie javascript”

Lebih banyak jawaban terkait untuk “Hapus semua cookie javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya