Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a cookie?

Is my function of creating a cookie correct? How do I delete the cookie at the beginning of my program? is there a simple coding?

function createCookie(name,value,days) 
function setCookie(c_name,value,1) {   document.cookie = c_name + "=" +escape(value); }  setCookie('cookie_name',mac);  function eraseCookie(c_name) {   createCookie(cookie_name,"",-1); } 
like image 429
kennedy Avatar asked Jan 27 '10 03:01

kennedy


People also ask

Can I delete one cookie?

To delete an individual cookie, select the cookie in the list, and click “Remove Selected”. To delete all cookies for a specific website, select the website folder and click “Remove Selected”.

How do I delete a cookie in Windows 10?

Delete cookies from a specific siteUnder Cookies and data stored, select Manage and delete cookies and site data > See all cookies and site data and search for the site whose cookies you want to delete. Select the down arrow to the right of the site whose cookies you want to delete and select Delete .

What is the shortcut to delete Cookies in Chrome?

In Chrome, click the vertical ellipsis button in the upper right corner. Select "More tools", then "Clear browsing data". Or, you can use the shortcut of pressing the Ctrl + Shift + Delete keys to bring up the same menu. This keyboard shortcut works on Chrome, Firefox, Edge, and Internet Explorer.


1 Answers

Try this:

function delete_cookie( name, path, domain ) {   if( get_cookie( name ) ) {     document.cookie = name + "=" +       ((path) ? ";path="+path:"")+       ((domain)?";domain="+domain:"") +       ";expires=Thu, 01 Jan 1970 00:00:01 GMT";   } } 

You can define get_cookie() like this:

function get_cookie(name){     return document.cookie.split(';').some(c => {         return c.trim().startsWith(name + '=');     }); } 
like image 149
ACP Avatar answered Sep 20 '22 15:09

ACP