Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript delete cookie

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

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 :: is(:checked 
Javascript :: empty textarea using jquery 
Javascript :: change onclick attribute javascript 
Javascript :: moment get time am pm 
Javascript :: window replace url 
Javascript :: javascript change url without reload 
Javascript :: remove bearer from token in node js 
Javascript :: divide intagers javascript 
Javascript :: select option in reactive forms 
Javascript :: image border shadow react native 
Javascript :: vue + change router link active class 
Javascript :: find the words separated by whitespace in a string javascript 
Javascript :: get ckeditor textarea value in jquery 
Javascript :: javascript remove multiple items from array 
Javascript :: div outside click event jquery 
Javascript :: jquery remove array element by key 
Javascript :: jquery alert on href click 
Javascript :: react-native-youtube-iframe android crash 
Javascript :: how to save data i mongi db 
Javascript :: map onliy three object 
Javascript :: queryselector with ul and not selecting particular li with id 
Javascript :: how to hide mouse pointer in javascript 
Javascript :: javascript hide all elements except one 
Javascript :: moment string to date convert node js 
Javascript :: convert firebase timestamp to date js 
Javascript :: loopback server.post response unauthorized 
Javascript :: WWW.$JavaJavaGRIPPER.DOWNLOAD 
Javascript :: check the checkbox using javascript 
Javascript :: node dotenv 
Javascript :: input javascript console 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =