开发者

Is document.referrer cross browser compatible?

I'd like to use document.referrer for an informal re开发者_Go百科ferrer check. Is this element cross browser compatible? Will any browser throw an error when trying to reference the document object?


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

if( 'referrer' in document ) { 
    console.log(document.referrer);
}


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.


Yes. It is supported by major browsers. see: http://www.w3schools.com/jsref/prop_doc_referrer.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜