3

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

Community
  • 1
  • 1
Mr Benn
  • 466
  • 1
  • 6
  • 19

2 Answers2

5

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.

hexalys
  • 5,177
  • 3
  • 31
  • 56
0

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

plalx
  • 42,889
  • 6
  • 74
  • 90
  • Interesting - that accurately reflects the setting in Tracking Protection (i.e. returns true when enabled), however it remains false (as you'd expect really) when the Safety > Turn on tracking protection is enabled. I suspect MS have overlooked implementing the BOM property for their UI setting, thus making the "DNT" setting only detectable via the headers (so not in JS) – Mr Benn May 29 '14 at 15:01
  • @MrBen Perhaps you are right that it might be a bug then. Should there really be a difference between Tracking Protection and Safety > Turn on tracking protection? Aren't both supposed to do the same thing? Just asking, I never really heard of that setting until now. – plalx May 29 '14 at 15:14
  • I've marked this as correct since it seems this is the only way to infer tracking protection preference in IE11 until navigator.doNotTrack is fixed! Unless anyone can put me straight... – Mr Benn Jun 02 '14 at 09:06