Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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();
Comment

javascript Clear All Cookies

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

clearing cookie in js

document.cookie.split(";")
  .forEach(function(c) { 
  	document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
Comment

js delete all cookies

function del_cookies() {
  /*Split Cookies into a two-dimensional array:*/
  var c_a = document.cookie.split (';').map(cookie => cookie.split('='));
  var c = 0;
  /*Repeat following prozess for the number of cookies*/
  while (c < c_a.length) {
    /*Get first element of every array inside the c_a array:*/
    var c_a_name = c_a[c][0];
    
    /*DEBUGGING: (logs the name of the cookies in the console)*/
    /* console.log(c_a[c][0]); */
    
    /*set the expire date to some date in the past to delete the cookie:*/
    document.cookie = c_a_name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
    /*increase c to get the next array*/
    c++;
  }
}
/*
  Note:
  
    This deleats ALL cookies!
    -----
	If this doesn't work for you, change the path for deleting the cookie.
    You may create new cookies, if it's the wrong path.
    -----
    Two-dimensional cookie array:
    [
    ['cookie_name_1', value_1],
	['cookie_name_2', value_2],
    ['cookie_name_3', value_3],
	]
*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: on hover add class on children jquery 
Javascript :: compose es6 
Javascript :: ajax post variable values 
Javascript :: scroll element by javascript 
Javascript :: strapi production build 
Javascript :: keypress event 
Javascript :: remove # url vuejs 
Javascript :: jquery on ready 
Javascript :: refresh page and run function after javascript 
Javascript :: javascript classlist add 
Javascript :: nuxt input mask 
Javascript :: replace all occurrences of a string in javascript 
Javascript :: get all entries in object as array hjs 
Javascript :: website edit js 
Javascript :: npx create-react-app current folder 
Javascript :: stackoverflow narrate text js 
Javascript :: javascript lowercase string except first letter of every word if there are ' 
Javascript :: “javascript remove last element from array 
Javascript :: bootstrap switch on change 
Javascript :: duplicates array js 
Javascript :: how to get href value of anchor tag in jquery in list 
Javascript :: js convert html to text 
Javascript :: html javascript type 
Javascript :: javascript element read attribute 
Javascript :: javascript get placeholder value 
Javascript :: getting data from form node 
Javascript :: jquery select element with two classes 
Javascript :: how to make a deep copy in javascript 
Javascript :: share link to whatsapp javascript 
Javascript :: regex to match string not in between quotes 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =