Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript delete cookie

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

how to destroy cookie in javascript

function delCookie(name){
	document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; 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 :: Converting file to base64 on Javascript client side 
Javascript :: text overflow ellipsis two lines react native 
Javascript :: concatenate multiple arrays javascript 
Javascript :: remove duplicates array.filter 
Javascript :: jquery post form async 
Javascript :: Conflicting peer dependency: react@18.0.0 npm WARN node_modules/react 
Javascript :: substr() javascript 
Javascript :: discord.js set playing tag 
Javascript :: my loader is continously loading js 
Javascript :: using html forms to define javascript variables 
Javascript :: nextjs open browser automatically 
Javascript :: js map through array and return array of objects 
Javascript :: jquery number counter 
Javascript :: javascript Compare two arrays regardless of order 
Javascript :: read multiple parameters in url in js 
Javascript :: javascript fromEntries 
Javascript :: jest listen EADDRINUSE: address already in use :::5000 jest 
Javascript :: javascript replaceall 
Javascript :: js combine arrays 
Javascript :: passportjs serializeuser 
Javascript :: javascript sort object 
Javascript :: base64 nodejs image 
Javascript :: create angular component using cli 
Javascript :: Javascript stringify with functions 
Javascript :: count vowels in a string javascript 
Javascript :: comment out in javascript 
Javascript :: js get english alphabet 
Javascript :: js array to string 
Javascript :: change text in javascript 
Javascript :: if clicked anything 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =