Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

http - Document.referrer empty when navigating from external url?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...