Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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],
	]
*/
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #delete #cookies
ADD COMMENT
Topic
Name
5+9 =