Javascript only detection of “Do not track” settings in IE11

偶尔善良 提交于 2019-12-06 09:05:10

问题


I would like to respect the DNT settings in all browsers using only javascript (I don't have server side access to the host server). I got the following from https://stackoverflow.com/a/16947583/266960

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

This works in all browsers but IE11 (specifically 11.0.9600.16428 run through [http://spoon.net/]), which does not seem to honour any of the above BOM properties (I tried setting the DNT preference via the Internet Options > Advanced > Security: "Always send a do not track header" and also via Safety > Turn on tracking protection).

Can anyone else confirm this is correct (i.e. a bug in IE11), or suggest a JS only method to detect those settings?

TIA Ben


回答1:


As per this answer from Microsoft: "The standard was updated" as of IE11, placing the doNotTrack property on the window object instead.

Not all browsers are up to date with this yet, only IE11 and Safari 6.1.1+ have updated at this time as per this window properties table.

As of this writing there is a current disagreement/discussion from Mozilla as to whether doNotTrack should be a window or navigator property.




回答2:


Have you tried with window.external.msTrackingProtectionEnabled(), which returns a boolean and is implemented in IE 9/10. I cannot test right now, but it's probably supported in IE 11 as well.

http://ie.microsoft.com/TEStdrive/Browser/DoNotTrack/Default.html



来源:https://stackoverflow.com/questions/23933650/javascript-only-detection-of-do-not-track-settings-in-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!