I'd like to use document.referrer for an informal referrer check. Is this element cross browser compatible? Will any browser throw an error when trying to reference the document object?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
The
document.referrer
property is described in the DOM spec:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95229140
So it should be supported cross-browser. However, you can easily detect if the implementation does support this property like
Yes. It is supported by major browsers. see: http://www.w3schools.com/jsref/prop_doc_referrer.asp
You can not depend on it to determine if the request is coming from a browser (many non-browser robots also send one). While it is supported by browsers their are also privacy programs to specifically not provide it. Sometimes this is done by a proxy server ... http://en.wikipedia.org/wiki/HTTP_referrer ... and If a website is accessed from a HTTP Secure (HTTPS) connection and a link points to a non-secure connection, then the referrer field is not sent.
So the answer is yes but with exceptions.