Check if third-party cookies are enabled

前端 未结 6 1406
既然无缘
既然无缘 2020-11-27 10:58

I have an application that needs to check whether the client browser has third-party-cookies enabled. Does anyone know how to do this in JavaScript?

6条回答
  •  星月不相逢
    2020-11-27 11:31

    ⚠️ Update: Multiple browsers are now implementing stricter privacy controls that may cause this test to give a "false negative" result, meaning that it will conclude that third-party cookies are disabled when they may in fact be enabled but blocked in use-cases similar to that of the test.


    Here's a pure JS solution not requiring any server-side code, so it can work from a static CDN: https://github.com/mindmup/3rdpartycookiecheck - the first script sets the cookie in the code, then redirects to a second script that will post a message to the parent window.

    You can try out a live version using https://jsfiddle.net/tugawg8y/

    client-side HTML:

    third party cookies are