Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing only specific cookies

How can I clear only two cookies using JavaScript?

I use the below code to set these cookies.

function setCookie(c_name, value, exdays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays==null) ? "" : ";expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}
like image 245
Varada Avatar asked May 12 '11 10:05

Varada


People also ask

Can you clear specific cookies?

Under the Browsing history section, select Settings. In the Website Data Settings dialog box, select View files. Scroll through the list of cookies to find the one you want to delete. Select a cookie and press Delete on the keyboard.

Can you selectively delete cookies in Chrome?

Or, easier yet, copy and paste: chrome://settings/siteData into the address bar and hit Enter. While you can scroll through the multitude of stored cookies here, it has a simple search feature that allows you to find the specific offending site cookie and delete it.

How do I selectively clear cookies in Safari?

Websites, third parties, and advertisers can store cookies and other data on your Mac. Remove stored cookies and data: Click Manage Website Data, select one or more websites, then click Remove or Remove All. Removing the data may reduce tracking, but may also log you out of websites or change website behavior.

Can you clear cookies and cache for one site?

1] Open Chrome and head to Settings. 2] Then, click on Site Settings > Storage. 3] Here, you'll see all the stored data for websites, including cache and cookies. 4] Select and clear the data for the website you want to.


1 Answers

A cookie is expired if the Expires parameter value is a date in the past. So just set the value to a date in the past:

function deleteCookie(c_name) {
    document.cookie = encodeURIComponent(c_name) + "=deleted; expires=" + new Date(0).toUTCString();
}
like image 171
Gumbo Avatar answered Oct 20 '22 18:10

Gumbo