Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to modify and delete cookie by JavaScript

Shulou Source: shulou.com Published: 2022-05-31 10:40:07 09月15日 Update

In this article, the editor introduces in detail "how JavaScript modifies and deletes cookie" with detailed content, clear steps and proper handling of details. I hope this article "how to modify and delete cookie in JavaScript" can help you solve your doubts.

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.

After reading this, the article "how to modify and delete JavaScript cookie" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Articles time same content name domain name path proper diva ideas new knowledge methods more steps users user names knowledge knowledge points articles details Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information macOS Microsoft NVidia