JavaScript document.referrer

document.referrer returns the URL of the page that linked to the current document when referrer information is available. It returns an empty string when no referrer is supplied, such as many direct/bookmark visits or when policy/privacy rules suppress it.

const referrer = document.referrer;
console.log(referrer);

Referrer visible to this page:

Why document.referrer may be empty or reduced Top ↑

Referrer information is controlled by browser behavior and Referrer Policy. Cross-origin navigation may provide only an origin rather than the complete source URL, and a site can intentionally send no referrer at all. Therefore, do not treat document.referrer as a guaranteed analytics identifier.

Original document.write() pattern and modern output Top ↑

The older page wrote the value while the document was parsing. For normal output, place it into an existing element instead:

const output = document.getElementById('referrerOutput');
output.textContent = document.referrer || '(no referrer supplied)';

How referrer information is used Top ↑

Referrer data can provide context about the route by which a visitor arrived, but modern analytics should combine it with campaign parameters and server-side request information rather than assuming the referrer is always present.

Server-side alternatives remain available in the original linked tutorials: get the referrer in PHP and referrer handling in the ASP tutorial.

Document Object Title of the Page




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer