Skip to content Skip to sidebar Skip to footer

Document.referrer Exists But Is Always Empty

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('re

Solution 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"

Post a Comment for "Document.referrer Exists But Is Always Empty"