I have a cookie structure something like below
name1=123abc; name2; name3=abcd1212; name4=1122hjhdff
Here I am trying to remove the name2, so that my structure will be like:
name1=123abc; name3=abcd1212; name4=1122hjhdff
I have looked into various posts which says to define past date for the specific name which you want to delete
var delete_cookie = function(name) {
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
};
delete_cookie('name2');
I am trying to use this, but I am not able to succeed. I also read various post saying that a 'HTTP' only cookie cannot be deleted by any scripting language.
I tried something like below and I highly doubt this will work, since I am altering document.cookie directly
function removeSelectedCookie() {
var val = " name2";
var arr = document.cookie.split(';');
var index = arr.indexOf(val);
arr.splice(index, 1);
document.cookie = arr.join(';');
}
I am not sure whether I am missing simple change here. Could someone help me on how to have this deleted or this cannot be deleted?