JS Delete Cookie is unsuccessful

Source: Internet
Author: User
Tags set cookie chrome developer chrome developer tools

Recently in a project, JS Delete cookie is always unsuccessful, and finally found that there is no specified cookie domain

JS Delete Cookie is to change the expiration time of the cookie, the expiration time of the cookie is set to the past, the following items must be specified

1.cookie Name

2.cookie value

3.cookie expiry time

4.cookie Domain

5.cookie Path

The above are indispensable, must have the ability to modify the cookie

The specific code is as follows:

1 /** Set Cookies2 * @param {cookie name}3 * @param {cookie value}4 * @param {set cookie domain}5 * @param {Expiration time (days)} [VarName]6      */7     functionSetcookie (name, value, domain, day) {8         varDate =NewDate ();9 TenDate.settime (Date.gettime () +1000*60*60*24*Day ); OneDocument.cookie = name+ ' = ' +value+ '; expires= ' +date+ ';d omain= ' +domain+ ';p ath=/'; A     } -  -     /** the * Get Cookies - * @return {[type]} [description] -      */ -     functionGetCookie (name) { +         vardata = Document.cookie.split ('; ')), -param = {}; +          for(vari = 0; i < data.length; i++) { AParam[data[i].split (' = ') [0].replace (/\s/, ')] = data[i].split (' = ') [1]; at         } -         returnParam[name]; -     } -  -     /** - * Delete Cookies in * Name: Delete cookie name - * domain: Domains in which you are located to      */ +     functionDelcookie (name, domain) { -Document.cookie = name+ ' = ' +getcookie (name) + '; expires= ' + (NewDate (1)) + ';d omain= ' +domain+ ';p ath=/'; the}

For example, now I want to delete _uij This cookie, I view the following cookie's domain as the. renren.com from the Chrome developer tools, application Panel cookie option (note that there is a. in front of Renren)

Delcookie (' _uij ', '. renren.com ');

You can delete it.

JS Delete Cookie is unsuccessful

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.