Document.referrer empty when navigating from external url?

前端 未结 1 921
失恋的感觉
失恋的感觉 2020-12-07 00:20

I have the following code:

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

This will not work if the previous page url is o

相关标签:
1条回答
  • 2020-12-07 01:03

    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.

    0 讨论(0)
提交回复
热议问题