Read the property. No arguments — just navigator.doNotTrack.
Expect a string or null. MDN documents "1", "0", or null.
Log it. Useful for demos and debugging legacy code.
Do not trust it alone. Sites historically ignored the preference.
Example 2 — Interpret the Value
Map the three possible results to plain-language labels.
JavaScript
function describeDnt(value) {
if (value === "1") return "prefer not to be tracked";
if (value === "0") return "tracking opted in";
return "no preference";
}
console.log(describeDnt(navigator.doNotTrack));
no preference
/* or the matching label for "1" / "0" */
How It Works
Pass the raw value. Use strict equality on the strings.
Handle "1". User asked not to be tracked.
Handle "0". User opted in to tracking.
Default for null. No preference expressed (or UI removed).
Example 3 — Prefer Global Privacy Control
For new code, check GPC when available instead of relying on DNT.
JavaScript
function privacyHint() {
if ("globalPrivacyControl" in navigator) {
return navigator.globalPrivacyControl
? "GPC: do not sell/share"
: "GPC: false / unset";
}
// Legacy only — do not depend on this for enforcement
return "DNT legacy: " + String(navigator.doNotTrack);
}
console.log(privacyHint());
Detect GPC first. Modern replacement path when the property exists.
Read the boolean.true means do not sell/share (MDN).
Fall back carefully. Only mention DNT for legacy awareness.
Teach the migration. Students learn what to use next.
Compatibility
Browser Support
Navigator.doNotTrack is Non-standard on MDN. The DNT specification is discontinued and the HTTP DNT header is Deprecated. Some browsers still expose the property for compatibility; others return null or remove DNT UI.
✓ Non-standard · Discontinued
Navigator.doNotTrack
Legacy compatibility only. Prefer navigator.globalPrivacyControl / Sec-GPC for modern privacy preference signals.
LegacyDo not use for new work
Google ChromeMay expose legacy DNT; do not rely on it
Legacy
Microsoft EdgeLegacy compatibility varies
Legacy
Mozilla FirefoxDNT setting removed (GPC preferred)
Legacy
Apple SafariLegacy / often unset
Legacy
OperaChromium-based legacy exposure
Legacy
navigator.doNotTrackLegacy
Bottom line: Learn the values for interviews and old codebases, then migrate privacy logic to Global Privacy Control and enforceable protections.
Frequently Asked Questions
It returns the user’s Do Not Track preference as "1" (prefer not to be tracked), "0" (user opted in to tracking), or null (no preference). It mirrors the DNT HTTP header (MDN).
No. MDN marks it Non-standard; the DNT specification is discontinued and the DNT HTTP header is Deprecated. Prefer stronger privacy tools such as Global Privacy Control.
Browsers are moving toward features like Global Privacy Control (navigator.globalPrivacyControl / Sec-GPC), third-party cookie restrictions, and other enforceable protections — not cooperative DNT headers.
MDN: many sites ignored the preference, so it was ineffective. The signal can also add fingerprint entropy that helps trackers identify users.
No. It is a read-only Navigator property reflecting a browser preference (where the UI still exists).
Per MDN: "1" if DNT is enabled, "0" if the user opted in for tracking, otherwise null.