有人能告诉我如何使用JavaScript检测Safari浏览器是否启用了防止第三方跟踪保护吗?
有人能告诉我如何使用JavaScript检测Safari浏览器是否启用了防止第三方跟踪保护吗?
您可以通过使用 iframe 进行快速测试,查看是否能够设置/读取第三方域名的 cookie。
例如:
<!DOCTYPE html>
<html>
<head>
<script>
function testThirdPartyCookies(callback) {
let iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = 'https://thirdparty.domain.com'; // Replace with a third-party domain
iframe.onload = function () {
try {
// Attempt to set a test cookie on the third-party domain
iframe.contentWindow.document.cookie = 'testcookie=1; path=/';
// Check if the test cookie was set successfully
let cookieEnabled = iframe.contentWindow.document.cookie.includes('testcookie=1');
callback(cookieEnabled);
} catch (error) {
// An error occurred, which might indicate that third-party cookies are blocked
callback(false);
} finally {
// Remove the iframe