javascript document.referrer 跨浏览器兼容吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5097808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is document.referrer cross browser compatible?
提问by buley
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?
我想使用 document.referrer 进行非正式的推荐人检查。这个元素跨浏览器兼容吗?尝试引用文档对象时,任何浏览器都会抛出错误吗?
回答by jAndy
The document.referrerproperty is described in the DOM spec:
该document.referrer属性在 DOM 规范中描述:
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95229140
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95229140
So it shouldbe supported cross-browser. However, you can easily detect if the implementation does support this property like
所以应该是支持跨浏览器的。但是,您可以轻松检测实现是否支持此属性,例如
if( 'referrer' in document ) {
console.log(document.referrer);
}
回答by Wayne
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.
您不能依赖它来确定请求是否来自浏览器(许多非浏览器机器人也会发送请求)。虽然浏览器支持它,但它们也是隐私程序,专门不提供它。有时这是由代理服务器完成的... http://en.wikipedia.org/wiki/HTTP_referrer... 如果从 HTTP 安全 (HTTPS) 连接访问网站并且链接指向非安全连接,则不发送引用字段。
So the answer is yes but with exceptions.
所以答案是肯定的,但有例外。
回答by user194076
Yes. It is supported by major browsers. see: http://www.w3schools.com/jsref/prop_doc_referrer.asp
是的。主要浏览器都支持它。见:http: //www.w3schools.com/jsref/prop_doc_referrer.asp

