The original always thought that as long as the Document.cookie object set JavaScript can simply set and delete cookie value in the browser side, many articles on the web is also taught, but recently found that the simple set of JavaScript Document.cookie value can not be completely deleted or change the cookie. Accidentally found an article gives the correct method, which is posted here.
Use JavaScript to clean up cookies first find the value corresponding to the name of the cookie, and then set it to expire:
The following methods are found for cookies:
function GetCookie2 (name) { var arr = document.cookie.match (New RegExp ("(^|)" +name+ "= ([^;] *)(;|$)")); if (arr! = null) return unescape (arr[2]); return null;}
When found, set to expire, remember to set domain and path, only these two parameters are exactly the same as the parameters you want to delete to delete it.
function Resetnfluent () {alert ("before=>" +document.cookie), var exp = new Date (); Exp.settime (Exp.gettime ()-1) var cval=getcookie2 (' name '), var Lanobj=document.getelementbyid (' lanoption '), var lansel=lanobj.value;alert (LanSel if (lansel== ' en ') {alert (' let\ ' s reset nfluent '); alert (' cval=> ' +cval); if (cval!=null) {document.cookie= "name=" + cval+ ";d omain=.example.com;expires=" +exp.togmtstring () + ";p ath=/";} Else{document.cookie= "Name=;d omain=.example.com;expires=" +exp.togmtstring () + ";p ath=/";}} Else{alert (' don\ ' t need reset nfluent ');} Alert ("after=>" +document.cookie);
As for how to view cookies in detail, such as path and domain, in Firefox can be viewed according to the following steps:
Tools->option->privacy->show Cookies
Original address
JavaScript the correct way to delete cookies (reproduced)