document.referrer存在,但始终为空 [英] document.referrer exists but is always empty

查看:2427
本文介绍了document.referrer存在,但始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS 8上的移动应用程序上工作。document.referrer似乎总是空的。我尝试使用以下方法检查它是否存在:

I am working on a mobile application on iOS 8. document.referrer seems to always be empty. I have tried to check if it exists by using:

if( 'referrer' in document ) {
    alert('referrer ' + document.referrer);
}

它会发出警报,但无论我是从另一个页面访问它,或者如果我是第一次访问该页面。我还添加了元标记:

and it throws an alert, but the value is always empty, whether I am accessing it from another page or if I am accessing the page for the first time. I have also included the meta tag:

<meta name="referrer" content="always">

我如何获得document.referrer的价值?

How do I get the value of document.referrer?

编辑:我也忘了提一下,我不在本地iOS应用程序上工作。我正在使用cordova以及HTML5和JS。

I also forgot to mention, that I am not working on a native iOS app. I am using cordova and HTML5 and JS.

推荐答案

由于我们对您的本机包装一无所知,因此可能发生了两件事:

Since we don't know anything about your native wrapper, it's possible there are a couple of things going on:


  1. document.referrer 来自HTTP标头 Referer (请注意历史拼写错误)。您的iOS代码中可能有某些内容正在设置或抑制该HTTP标头。

  1. document.referrer is derived from the HTTP header Referer (note historical misspelling). It's possible that something in your iOS code is setting or suppressing that HTTP header.

如果您的Web应用是使用带有文件的URL托管的模式(如 file:///foo.html ),浏览器引擎将不会设置HTTP Referer 标头可防止敏感信息泄漏。 (例如,如果您有一个链接到远程站点的本地网页,则不想将本地文件名发送到远程Web服务器。)

If your web app is hosted using URLs with file schema (as in file:///foo.html), browser engines will not set the HTTP Referer header to prevent leakage of sensitive information. (You wouldn't want to send local filenames to a remote webserver if, for example, you had a local webpage that linked out to a remote site.)

如果发现其中之一正在发生,则可以按照 Referer 标头://stackoverflow.com/questions/7913305/specifying-http-referer-in-embedded-uiwebview>在嵌入式UIWebView中指定HTTP引用网址

If you find that one of these is happening, you can manually set the Referer header as described in "Specifying HTTP referer in embedded UIWebView"

这篇关于document.referrer存在,但始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆