function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
taradyntaradyn 

Delete cookie based on id

I've created a cookie as shown: 
cookieJar c = new cookieJar(p.productid, selSize, selColour, String.valueOf(p.qtyToBuy));
and append any newly added data to the cookie:  
cookieJar c = new cookieJar(p.productid + ',' + pid, selSize + ',' + psize, selColour + ',' + pcol ,String.valueOf(p.qtyToBuy) + ',' + pqty);

I would like to delete the cookie data based on their productid. But not sure on how to do so. I've read the cookie class docs and found this:

maxAge
Type: Integer
A number representing how long a cookie is valid for in seconds. If set to less than zero, a session cookie is issued. If set to zero, the cookie is deleted.


How do I delete the data?
Subramani_SFDCSubramani_SFDC
function loaded() {
     document.cookie = "v0=1;";
     document.cookie = "v1=2;";
     alert(document.cookie);
     }


function deletecook() {
    var d = new Date();
    document.cookie = "v0=1;expires=" + d.toGMTString() + ";" + ";";
     alert(document.cookie);
     }

Call this method on the "onload " event of the page--> onload="loaded();"

<!--add this code to html---><a href="javascript:deletecook();">Delete Cookie</a>