Wednesday, 15 February 2012

how to read and delete a Cookie with javascript? -



how to read and delete a Cookie with javascript? -

allcookies contents list of browser cookies. want delete cookies function delcookie(), delete first cookie, , not others cookies. , how update cookie???

<input type="button" value="delete" onclick="delcookie()"> <input type="button" value="update" onclick="modcookie()"> <select multiple id="allcookies" size="5"> <!-- cookies content--> </select><br> function delcookie() { if (confirm('are u sure?')) { var e = document.getelementbyid("allcookies"); var struser = e.options[e.selectedindex].value; document.cookie = encodeuricomponent(struser) + "=deleted; expires=" + new date(0).toutcstring(); } }

it delete first cookie, , not others cookies.

the selectedindex property of <select> element returns index of first selected option. check of them in multiple select, need iterate options collection:

var os = document.getelementbyid("allcookies").options; (var i=0; i<os.length; i++) { if (os[i].selected) { var struser = os[i].value; … } }

and how update cookie???

just overwrite cookie, i.e. utilize same method when creating them.

javascript cookies

No comments:

Post a Comment