Document: referrer property

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("DOM")}}

The **referrer** read-only property of the {{domxref("Document")}} interface returns the URI of the page that linked to this page.

Value

The value is an empty string if the user navigated to the page directly (not through a link, but, for example, by using a bookmark). Because this property returns only a string, it doesn't give you document object model (DOM) access to the referring page.

Inside an {{HTMLElement("iframe")}}, the Document.referrer will initially be set to the {{domxref("HTMLAnchorElement/href", "href")}} of the parent's {{domxref("Window/location", "Window.location")}} in same-origin requests. In cross-origin requests, it's the {{domxref("HTMLAnchorElement/origin", "origin")}} of the parent's Window.location by default. For more information, see the Referrer-Policy: strict-origin-when-cross-origin documentation.

Examples

The following will log a string containing the document's referrer.

js
console.log(document.referrer);

If the user navigated to the page via a link like <a href="https://www.w3.org/">W3</a>, then it will output the previous domain like developer.mozilla.org. If the user navigated to the page directly, it will output an empty string.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}