如何通过JavaScript访问HTTP请求标头字段? [英] How do I access the HTTP request header fields via JavaScript?

查看:163
本文介绍了如何通过JavaScript访问HTTP请求标头字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的客户端JavaScript中捕获HTTP请求头字段,主要是Referer和User-Agent。我如何访问它们?

I want to capture the HTTP request header fields, primarily the Referer and User-Agent, within my client-side JavaScript. How may I access them?

Google Analytics设法通过JavaScript将您嵌入页面中的数据获取,所以它绝对有可能。

Google Analytics manages to get the data via JavaScript that they have you embed in you pages, so it is definitely possible.


相关:

使用JavaScript访问网页的HTTP标头


推荐答案

如果您想访问referrer和user-agent,那些可用于客户端Javascript,但不能直接访问标题。

If you want to access referrer and user-agent, those are available to client-side Javascript, but not by accessing the headers directly.

要检索推荐人,请使用 document.referrer

要访问用户代理,请使用 navigator.userAgent

To retrieve the referrer, use document.referrer.
To access the user-agent, use navigator.userAgent.

其他人有籼稻ted,HTTP标头不可用,但你明确询问了referer和user-agent,它们可以通过Javascript获得。

As others have indicated, the HTTP headers are not available, but you specifically asked about the referer and user-agent, which are available via Javascript.

这篇关于如何通过JavaScript访问HTTP请求标头字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆