Asked 3 years ago
20 May 2021
Views 585
yogi

yogi posted

document.referrer in Javascript

how document.referrer works in Javascript ?
how can i use document.referrer in Javascript ?
what are the limitation of document.referrer in Javascript ?

QuickIos

QuickIos
answered Apr 25 '23 00:00

document.referrer is a property of the Document Object Model (DOM) in JavaScript that returns the URL of the document that linked to the current document.

For example, if a user clicks on a link on website A and is taken to website B, then document.referrer on website B will return the URL of website A.

Here's an example of how to use document.referre r in JavaScript:



// get the referrer URL
var referrerURL = document.referrer;

// output the referrer URL to the console
console.log("Referrer URL: " + referrerURL);

Note that document.referrer will return an empty string if there is no referrer. This can happen if the user typed the URL directly into the address bar or if the referrer was blocked by the user's browser or a privacy extension.
Post Answer