2

Is there a way to block all cookies sent to client from a webpage using javascript? Is should not allow third-party cookies from iframes or other scripts as well.

I've thought about it, like a listener that triggers a set cookie event and block it.

Alexandru R
  • 8,560
  • 16
  • 64
  • 98
  • Could you elaborate more? The cookies are sent when the page is requested, i.e. *before* the JS is executed. Also, if someone requests your site, why would you want to prevent setting cookies from your site? – Felix Kling May 01 '12 at 13:20
  • So, you want the server to send the client some code, that the client will run, to prevent the server sending the client more cookies? – Alnitak May 01 '12 at 13:20
  • 1
    My **first hit** with google gave me a duplicated... [How to capture the “JavaScript SetCookie event” in a WebBrowser?](http://stackoverflow.com/q/3664613/601179) . And the answer is **NO, it can't be done** – gdoron May 01 '12 at 13:20
  • @gdoron — It isn't a duplicate. This question is about blocking cookies. The event listener is just a suggested approach. – Quentin May 01 '12 at 13:28
  • @quentin indeed, the event listener is a suggested approach. It seems is not possible... My goal is to block all cookies that are added by a browser request, from any source (javascript, iframes, server). I can easily delete the ones form the server, but I cannot read nor write the ones that are added by javascript code (ex: Google Analytics) or iframes (facebook like iframes). – Alexandru R May 02 '12 at 13:45
  • Block other third party scripts, that's setting cookies using [GDPR solution like this](https://app.cookieyes.com) – mujuonly Sep 16 '19 at 12:01

1 Answers1

3

No, it isn't possible.

You could fake it for the current domain by polling the cookies and deleting them as you spot them (this wouldn't work for cookies marked as http only) but you can't touch cookies from other origins using JavaScript.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335