Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

How to delete cookie using javascript

  • 4 个回答
  • 16 人有此问题
  • 5 次查看
  • 最后回复者为 shivshankar.k

more options

Hi All,

I am working UI Automation. We are using javascript injection for automation. One of the features we need is to ability set / unset cookies.

I am able to set cookie using javascript, but I can't delete / unset a cookie. I am using below script to unset cookie.

document.cookie = 'cookie_name=; path=/; domain=.mycompany.com; expires=Thu, 01 Jan 1970 00:00:00 GMT';

If I try to alert document.cookie, it shows empty string. However, I can still see the cookie in browser after the javascript execution is complete.

Can someone suggest what I might be doing wrong?

P.S. I am on FF v17.0.3 esr on RHEL 5.

Thanks, Shiv

Hi All, I am working UI Automation. We are using javascript injection for automation. One of the features we need is to ability set / unset cookies. I am able to set cookie using javascript, but I can't delete / unset a cookie. I am using below script to unset cookie. document.cookie = 'cookie_name=; path=/; domain=.mycompany.com; expires=Thu, 01 Jan 1970 00:00:00 GMT'; If I try to alert document.cookie, it shows empty string. However, I can still see the cookie in browser after the javascript execution is complete. Can someone suggest what I might be doing wrong? P.S. I am on FF v17.0.3 esr on RHEL 5. Thanks, Shiv

所有回复 (4)

more options

Hey Shiv- This forum is for issues with the browser. However, I was able to find this article on MDN, which may help you:

https://developer.mozilla.org/en-US/docs/Web/API/document.cookie

Good luck!

more options

Thanks rbillings for responding. My code does exactly what is mentioned in that link, but no luck.

You mentioned that this forum is for issues related to browser. Is my question not in that category ? If not, can you please help me point to correct forum ? Thanks for bearing with newbie questions :)

Many Thanks, Shiv

more options

Hi Shiv- Your question involves the browser, but is more about UI automation & javascript. It requires help with code, and this forum is designed to help with UI, not code. I would recommend using sites that help with code [such as stackoverflow] to get more feedback about your specific issue. Sorry there isn't a forum for automation [and we're always glad to hear from newbies!]

more options

Got you, thanks so much :)