首页 \ 问答 \ 如何通过JavaScript访问HTTP请求头域?(How do I access the HTTP request header fields via JavaScript?)

如何通过JavaScript访问HTTP请求头域?(How do I access the HTTP request header fields via JavaScript?)

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


Google Analytics(分析)设法通过JavaScript嵌入您的页面来获取数据,因此绝对有可能。

有关:
通过JavaScript访问网页的HTTP头


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 manages to get the data via JavaScript that they have you embed in you pages, so it is definitely possible.

Related:
Accessing the web page's HTTP Headers in JavaScript


原文:https://stackoverflow.com/questions/220149
更新时间:2023-05-14 06:05

最满意答案

我们经历了同样的事情,因为我们有一个在Windows和Web应用程序中运行的.DLL,你已经找到了确定哪个是哪个的方法。

public bool IsWebApp()
{
    return (HttpContext.Current != null);
}

然后在您的应用程序中,您只需查询:

if ( this.IsWebApp() )
{
    //do webby stuff...
}

We went through the very same thing, as we have a .DLL that runs in both a Windows and a Web app and you've already nailed the way to determine which is which.

public bool IsWebApp()
{
    return (HttpContext.Current != null);
}

Then within your application, you just query:

if ( this.IsWebApp() )
{
    //do webby stuff...
}

相关问答

更多
  • 这个问题很可能是由于没有使用@Suspendable注解来注释流中调用的函数而导致的。 这可以是FlowLogic.call ,也可以是FlowLogic.call调用的函数(例如,如果您将此函数重写为CollectSignaturesFlow调用的一部分, CollectSignaturesFlow )。 如果使用以下命令行标志运行流测试: -Dco.paralleluniverse.fibers.verifyInstrumentation=true 然后,如果缺少注释会导致错误,则会突出显示。 但是, ...
  • 我们经历了同样的事情,因为我们有一个在Windows和Web应用程序中运行的.DLL,你已经找到了确定哪个是哪个的方法。 public bool IsWebApp() { return (HttpContext.Current != null); } 然后在您的应用程序中,您只需查询: if ( this.IsWebApp() ) { //do webby stuff... } We went through the very same thing, as we have a .DLL ...
  • 您可以使用vm组件在CamelContext实例之间发送交换。 http://camel.apache.org/vm.html Create a route to be shared consuming (from) with the vm: endpoint, and reference it from other routes using the same endpoint name. Split out the integration logic that you want to share into ...
  • 是的,这是它应该如何完成的,你可以将程序集清单嵌入到可执行文件中(好吧,资源部分)。 这就是RT_MANIFEST资源类型的用途。 清单资源有两种默认类型 - 进程清单,在进程创建期间使用ID CREATEPROCESS_MANIFEST_RESOURCE_ID(1),以及在DLL加载期间使用ID为ISOLATIONAWARE_MANIFEST_RESOURCE_ID(2)的隔离感知清单。 有几种用法(主要是Click-once部署),说明了使用RT_MANIFEST在子DLL中嵌入无注册COM清单的能力。 ...
  • 好的,我想我在这里找到了答案 。 它说: 默认情况下,在Windows 7和未来的Windows版本中,清单中没有兼容性部分的应用程序将接收Windows Vista行为 因此,如果您的清单中没有任何内容 ,Vista就是您所获得的。 阅读本文的其余部分,您可以做的最好的是获取Windows 7而不是Windows 8,那么这可能是Store Apps特有的内容吗? 编辑 好的,我终于找到了Windows 8所需的条目:
    是的,这是可能的(没有任何服务帮助)。 但我甚至无法打开进程句柄 您的进程是否启用了SE_DEBUG_PRIVILEGE权限? 使用此权限,您可以打开具有所有访问权限的系统进程(如果它不受保护(smss.exe,csrss.exe,services.exe)),并在CreateProcessAsUser ()中使用该句柄,或者使用UpdateProcThreadAttribute(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS)启用了SE_ASSIGNPRIMARYTOKEN_PR ...
  • 从您的想法开始,您可以将$this作为参数传递给您的回调 但请注意, 您的回调 (未在您的类中声明) 将无法访问受保护的私有属性/方法 - 这意味着您必须设置公用方法才能访问这些属性 。 你的课堂会看起来像这样: class myObject { protected $property; protected $anotherProperty; public function configure($callback){ if(is_callable($callback)){ / ...
  • 看来我的问题经常发生在处理你无法访问的exe时(例如,允许你直接在文本框中编写C#代码的应用程序,然后自编译,你无法访问编译,调试或运行处理)。 经过大量的调试后,我决定转移到NLog,它完美地工作并阅读了一些评论[这里],我相信NLog比Log4Net更好。 1 It seems my problem occurs often when dealing with exe that you don't have access to (e.g. apps that allow you to write C# ...
  • 您应该在不同的appdomain中运行脚本主机,并使用沙盒API通过Evidence属性设置安全策略 You should run scripting host in different appdomain, and setup Security Policies via Evidence property using sandboxing API
  • 这似乎是一个非常有趣的问题。 您的代码的问题是每次执行limitedEval都会生成新函数。 这意味着使用var关键字创建的任何变量都只存在于该函数的上下文中。 你真正需要的是每个上下文有1个函数并重用该函数的上下文。 最明显的方法是使用生成器 。 生成器本质上是可以暂停然后重新启动的函数。 // IIFE to store gen_name var limitedEval = function() { // Symbol for generator property so we don't pol ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。