从外部url导航时,Document.referrer为空吗? [英] Document.referrer empty when navigating from external url?
问题描述
我有以下代码:
var previousPageUrl = document.referrer;
alert(previousPageUrl);`
如果上一页的网址为任何外部网站,即不是我的申请。
例如:
如果我在第1页并转到我的应用程序的第2页,然后我将在第2页载入第1页的引荐来源网址,但是当我转到外部网站说www.google.com时,再次回到第1页时,我不会得到www。
$ b
由于链接点击或基于JavaScript的导航,导航时通常会在不相关的网站之间传递参考网址。如果用户使用浏览器的Chrome(例如地址栏,后退/前进按钮/等)导航,则不会发送引用URL。
为了安全/隐私的原因,引用者从HTTPS站点导航到HTTP站点时(例如从 https://google.com 到http://example.com )。它也可以通过各种JavaScript和HTML技巧故意剥离。没有办法禁用此行为以获取引荐网址(如果已被剥离)。
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.
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.
这篇关于从外部url导航时,Document.referrer为空吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!