Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document.referrer empty when navigating from external url?

Tags:

dom

http

I have the following code:

var previousPageUrl= document.referrer;
alert(previousPageUrl);

This will not work if the previous page url is of any external site, i.e., not of my application.

For example:

If I am in Page 1 and went to Page 2 of my application then I will get page 1 url in referrer in Page 2 load but when I go to external site say www.google.com then again when I come back to page 1 the I will not get www.google.com as referrer url.

Can Somebody tell to resove this issue.

like image 973
Vijay Avatar asked Oct 18 '13 17:10

Vijay


People also ask

Why is document referrer empty?

For security/privacy reasons, the Referer URL is stripped out when navigating from a HTTPS site to a HTTP site (e.g. from https://google.com to http://example.com). It can also be deliberately stripped out via a variety of JavaScript and HTML tricks.

What does Document referrer do?

The referrer property returns the URL of the document that loaded the current document.


1 Answers

Generally, Referer URLs are passed between unrelated sites when navigation occurs due to a link click or JavaScript-based navigation. Referer URLs are NOT sent if the user uses the browser's chrome (e.g. address bar, back/forward buttons/etc) to navigate.

For security/privacy reasons, the Referer URL is stripped out when navigating from a HTTPS site to a HTTP site (e.g. from https://google.com to http://example.com). It can also be deliberately stripped out via a variety of JavaScript and HTML tricks. There is no way to disable this behavior to get the Referer URL if it has been stripped.

like image 142
EricLaw Avatar answered Sep 23 '22 00:09

EricLaw