有没有可能检查与Firefox的Firefox DNT的价值? [英] Is it possible to check the value of Firefox DNT with javascript?

查看:181
本文介绍了有没有可能检查与Firefox的Firefox DNT的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有什么办法可以检查javascript的用户是否有用户已经设置DNT开启或关闭在Firefox(或没有设置任何偏好),而无需从服务器的帮助?

解决方案

我认为您正在寻找 navigator.doNotTrack

  console.log(window.navigator.doNotTrack); 
//如果启用了DNT,则打印是否则这是Firefox中的未指定

MDN解释说,在Firefox中:


当do-not-track头发送1时, navigator.doNotTrack 为yes。未设置标题时, navigator.doNotTrack 为未指定。当头文件发送0(当前在Firefox中不支持)时, navigator.doNotTrack 是no。

在其他浏览器中:


IE9,Opera 12和Safari 5.1是基于此版本的早期版本navigator.doNotTrack是为do-not-track头部发送的值。
$ b IE9使用供应商前缀,即 navigator.msDoNotTrack



$ p







$ b

  var isDNT = navigator.doNotTrack ==yes|| navigator.doNotTrack ==1|| 
navigator.msDoNotTrack ==1;


I'm working on a javascript advertising engine, and I would like for it to respect Firefox DNT header.

Is there any way javascript can check if the user has set DNT to on or off in firefox (or has set no preferences) without getting help from the server?

解决方案

I think you're looking for navigator.doNotTrack:

console.log(window.navigator.doNotTrack); 
// prints "yes" if DNT is enabled; otherwise this is "unspecified" in Firefox

MDN explains that in Firefox:

When the do-not-track header sends "1", navigator.doNotTrack is "yes". When the header is unset, navigator.doNotTrack is "unspecified". When the header sends "0" (currently unsupported in Firefox), navigator.doNotTrack is "no".

In other browsers:

IE9, Opera 12, and Safari 5.1 are based on an earlier version of this specification where navigator.doNotTrack is the value sent for the do-not-track header.

IE9 uses a vendor prefix, i.e., navigator.msDoNotTrack

So, you might detect DNT in general by doing:

var isDNT = navigator.doNotTrack == "yes" || navigator.doNotTrack == "1" || 
              navigator.msDoNotTrack == "1";

这篇关于有没有可能检查与Firefox的Firefox DNT的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆