document.referrer exists but is always empty

核能气质少年 提交于 2020-01-24 15:12:12

问题


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:

  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.

  2. 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.)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!