How to modify and delete cookie in JavaScript
This article mainly introduces "how to modify and delete cookie in JavaScript" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "how to modify and delete cookie in JavaScript" article can help you solve the problem.
How JavaScript modifies and deletes cookie
This gives us a way to modify and delete cookie-directly overwriting the original cookie.
For example, there is a cookie like this:
Username=itxueyuan;expire=1369929124191;path=/;domain=www.csstop.com
Change the user name to "JavaScript" and set it to expire one day later:
Var date=new Date ()
Var cookieExpire=date.getTime () + 24036001000
/ / when modifying cookie, the name, path and domain name must be the same
[xss_clean] = "username=JavaScript; expire=" + cookieExpire + "; path=/;domain=www.csstop.com"
Delete the cookie
How JavaScript modifies and deletes cookie
Var date=new Date ()
Var cookieExpire=date.getTime ()-1000; / / set to a past time
/ / when deleting a cookie, the name, path, and domain name must be the same
[xss_clean] = "username=JavaScript; expire=" + cookieExpire + "; path=/;domain=www.csstop.com"
Note: in order to delete a cookie, you can set its expiration time to a past time.
This is the end of the introduction on "how to modify and delete cookie in JavaScript". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.