项目作者: jonidelv

项目描述 :
Check if third party cookies 🍪 are supported ✅
高级语言: HTML
项目地址: git://github.com/jonidelv/third-party.git
创建时间: 2016-11-01T19:32:48Z
项目社区:https://github.com/jonidelv/third-party

开源协议:

下载


Third party cookie check for browsers

A simple, static, passive (CDN-compatible) way of checking if third party cookies are enabled in a browser.
Consists on an script that will set a cookie, and post a message depending on if the
cookie is present or not.

Deploy the scripts somewhere on a different domain from the main application, then load them similar to the
example below:

  1. <body>
  2. <script>
  3. var receiveMessage = function (evt) {
  4. if (evt.data === 'third-party-cookies-enabled') {
  5. console.log('thid party cookies are not supported');
  6. } else if (evt.data === 'third-party-cookies-disabled') {
  7. console.log('thid party cookies are supported');
  8. }
  9. };
  10. window.addEventListener('message', receiveMessage, false);
  11. </script>
  12. <iframe src="LOCATION_OF_THE_SCRIPTS/start.html" style="display:none" ></iframe>
  13. </body>

It’s also a good idea to set up a timeout that will automatically label third party cookies as unsupported if no recognised event comes back
after a while, just in case network fails.

Live example

Thanks to github pages, the scripts are hosted already at https://jonidelv.github.io/third-party/start.html — so you can use that as a live
version. For production, it’s better to deploy somewhere under your control.