问题
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">
How do I get the value of document.referrer?
EDIT: I also forgot to mention, that I am not working on a native iOS app. I am using cordova and HTML5 and JS.
回答1:
Since we don't know anything about your native wrapper, it's possible there are a couple of things going on:
document.referrer
is derived from the HTTP headerReferer
(note historical misspelling). It's possible that something in your iOS code is setting or suppressing that HTTP header.If your web app is hosted using URLs with
file
schema (as infile:///foo.html
), browser engines will not set the HTTPReferer
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.)
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"
来源:https://stackoverflow.com/questions/27742153/document-referrer-exists-but-is-always-empty