Document.referrer is a read-only instance property that returns the URL of the page that linked here, or an empty string on direct visits. Learn MDN’s logging example, how it differs from documentURI, Referrer-Policy effects, and five hands-on examples.
01
Kind
Read-only property
02
Returns
string (URL)
03
Empty?
Direct visit
04
Not
DOM access
05
Policy
Referrer-Policy
06
Status
Baseline
Fundamentals
Introduction
When a user clicks a link from one site to another, the browser often sends a Referer HTTP header (note the historical spelling) telling the destination where the click came from. In JavaScript, document.referrer exposes that information as a string on the current page.
MDN: the property returns the URI of the page that linked to this page. The value is an empty string if the user navigated directly — for example via a bookmark or by typing the address.
💡
String only — not a Document reference
MDN: because referrer returns only a string, it does not give you DOM access to the referring page. You cannot read elements from the previous page through this property.
A read-only instance property on Document. Its value reflects how the user arrived at this document.
Value — previous page URI string, or "" on direct navigation (MDN).
Read-only — set by the browser from navigation and policy; not assignable.
No DOM — string URL only; no reference to the other document (MDN).
Iframes — same-origin may use parent URL; cross-origin may send origin only (MDN, Referrer-Policy).
Status — Baseline Widely available since July 2015 (MDN).
Foundation
📝 Syntax
JavaScript
document.referrer
Value
A string — the referring page URI, or "" when there is no referrer (MDN).
MDN example — log the referrer
JavaScript
console.log(document.referrer);
MDN: if the user clicked a link like <a href="https://example.com">Example</a> on another site, document.referrer may contain that site’s URL. On a direct visit, it outputs an empty string.
Compare
⚖️ Referrer vs Current Page URLs
Property
Meaning
Typical value
document.referrer
Previous page that linked here
URL string or "" (this page)
document.documentURI
This document’s address
Current page URL
document.URL
Same as documentURI (MDN)
Current page URL
location.href
Current location (navigable)
Current page URL
document.domain
Current document domain
Hostname / domain string
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read referrer
document.referrer
Direct visit?
document.referrer === ""
From a link?
document.referrer !== ""
Parse hostname
new URL(document.referrer).hostname (if non-empty)
Privacy
Referrer-Policy may trim or hide referrer
MDN status
Baseline Widely available (since Jul 2015)
Snapshot
🔍 At a Glance
Four facts about document.referrer.
Type
string
Read-only
Means
previous URL
Where from
Empty
""
Direct nav
Status
baseline
Widely available
Compare
📋 referrer vs documentURI
document.referrer
document.documentURI
Points to
Previous page (if any)
This page
Direct visit
"" (MDN)
Current URL
Use case
Traffic source / analytics
Current address
DOM access to other page?
No (MDN)
N/A
Hands-On
Examples Gallery
Examples follow MDN Document: referrer. In try-it labs opened directly, document.referrer is usually empty — that is expected.
📚 Getting Started
Read and interpret the referrer string.
Example 1 — Read document.referrer
Log the referring page URL, or an empty string on direct navigation.
JavaScript
console.log(document.referrer);
// "" when opened directly in try-it
Document.referrer is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.referrer
Read-only string — URI of the page that linked here, or empty on direct navigation.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.referrerExcellent
Bottom line: Use document.referrer for lightweight source detection. Remember Referrer-Policy may limit the string, and never use it alone for security.
Wrap Up
Conclusion
Document.referrer tells you which page (if any) linked the user to the current document. It is a read-only string — empty on direct visits — and complements documentURI for understanding navigation context.
Parse with new URL() inside try/catch when non-empty
Compare with documentURI for current vs previous URL
Respect Referrer-Policy when designing your own links
Treat referrer as hint data, not proof of identity
❌ Don’t
Assign to document.referrer
Expect DOM access to the referring page
Rely on referrer for authentication or authorization
Assume the full URL is always sent cross-origin
Confuse referrer with location.href (current page)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.referrer
Previous page URL — or empty on direct visits.
5
Core concepts
🔗01
Returns
string URL
API
🚫02
Empty
direct nav
MDN
📄03
Not DOM
string only
MDN
🔒04
Policy
may trim
Privacy
🌐05
vs URI
prev vs now
Compare
❓ Frequently Asked Questions
A string with the URI of the page that linked to this page. MDN: it is an empty string if the user navigated directly (bookmark, typed URL, etc.).
No. MDN marks Document.referrer as Baseline Widely available (since July 2015). It is a standard read-only Document instance property.
No. MDN notes referrer returns only a string — it does not give DOM access to the previous page.
Direct navigation, privacy settings, Referrer-Policy headers/meta tags, or HTTPS-to-HTTP transitions can strip or limit the referrer (MDN discusses policy behavior).
documentURI is this page's address. referrer is the previous page's address (where the user came from), or empty when there is none.
No. It is read-only. Referrer is set by the browser based on navigation and policy; scripts cannot change it.
Did you know?
The HTTP header is spelled Referer (one r) due to a historical typo in the original specification, while the JavaScript property is correctly spelled document.referrer with two r’s.