最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cookies - How to detect if Prevent Cross-site tracking is active on Safari 13 with javascript - Stack Overflow

programmeradmin0浏览0评论

I would like to detect when Prevent Cross-site tracking is active in a browser using JavaScript.

My challenge is trying to find a method to detect this and show a warning popup to the user when this cross-site tracking is disabled by a users browser. This became essential after Safari 13 disabled it as default. I believe this might be helpful for people who are using cookies on iframes.

There are some ways such as

Check if third-party cookies are enabled

and

which are trying to bypass this security feature with using different methods and some of them are not valid anymore.

Basically what I try to achieve is from an iframe, try to detect Prevent Cross-site tracking is enabled on the browser using JavaScript.

I tried using this code:

var receiveMessage = function (evt) {
  if (evt.data === 'MM:3PCunsupported') {
    document.getElementById('result').innerHTML = 'not supported';
  } else if (evt.data === 'MM:3PCsupported') {
    document.getElementById('result').innerHTML = 'supported';
  }
};
window.addEventListener("message", receiveMessage, false);

However, this solution doesn't seem to work any more.

I would like to detect when Prevent Cross-site tracking is active in a browser using JavaScript.

My challenge is trying to find a method to detect this and show a warning popup to the user when this cross-site tracking is disabled by a users browser. This became essential after Safari 13 disabled it as default. I believe this might be helpful for people who are using cookies on iframes.

There are some ways such as

Check if third-party cookies are enabled

and

https://gist.github./iansltx/18caf551baaa60b79206

which are trying to bypass this security feature with using different methods and some of them are not valid anymore.

Basically what I try to achieve is from an iframe, try to detect Prevent Cross-site tracking is enabled on the browser using JavaScript.

I tried using this code:

var receiveMessage = function (evt) {
  if (evt.data === 'MM:3PCunsupported') {
    document.getElementById('result').innerHTML = 'not supported';
  } else if (evt.data === 'MM:3PCsupported') {
    document.getElementById('result').innerHTML = 'supported';
  }
};
window.addEventListener("message", receiveMessage, false);

However, this solution doesn't seem to work any more.

Share Improve this question edited May 8, 2022 at 23:43 Heretic Monkey 12.1k7 gold badges61 silver badges131 bronze badges asked May 5, 2020 at 16:03 Berk ÖzelBerk Özel 6077 silver badges15 bronze badges 2
  • did u find a solution to it ever? – Sana Commented Nov 9, 2023 at 21:31
  • I don't think a pure JS solution is possible because of the nature of what you're trying to detect, either the browser gives up the info or you use the solution in Alan H's answer from the post you linked. It explains everything you'd need to know to build your own solution and there's discussion in the ments for fixing issues that have e up over the years. – Matthew Ludwig Commented Dec 10, 2024 at 6:31
Add a ment  | 

1 Answer 1

Reset to default 0

You can try using Google Analytics on your site and adding code to detect if it loads. If it doesn't load, then its likely that tracker blockers are active.

Example:

<script>
var active;
</script>
<script src="https://googletagmanager./…" onerror="active = 1;"></script>
<script>
if (active !== 1) {
alert('Prevent cross site tracking is disabled');
} else {
alert("Ok")
}
</script>
发布评论

评论列表(0)

  1. 暂无评论