Can javascript delete a cookie set by http header?

15,612

Yes, javascript can delete a cookie set by HTTP headers unless it is specifically a HTTPOnly cookie.

The cookie must also be from the same domain as the javascript.

See also http://www.quirksmode.org/js/cookies.html and Clearing all cookies with JavaScript

Share:
15,612

Related videos on Youtube

HOT.CHO
Author by

HOT.CHO

A Frontend engineer...

Updated on June 04, 2022

Comments

  • HOT.CHO
    HOT.CHO almost 2 years

    I try to delete cookie set by http header but doesn't work. What's the different between http-set cookie and javascript-set cookie ?

    • CodeCaster
      CodeCaster about 11 years
      The answer is in here: How to Delete Session Cookie?. If a cookie is set with HttpOnly, you cannot access it from JS.
    • penguat
      penguat about 11 years
      Are they HTTPOnly cookies? Can your JavaScript read them?