简体   繁体   English

如何将浏览器用户代理 Header 更改为 javaScript?

[英]How to change browser User-Agent Header with javaScript?

Following code changes property printed (when accessed through javaScript) by browser console and not the actual Use-Agent string sent with the header.以下代码更改了浏览器控制台打印的属性(通过 javaScript 访问时),而不是使用 header 发送的实际 Use-Agent 字符串。

Object.defineProperty(navigator, 'userAgent', {
    get: function () { return 'Mozilla/5.0 (Windows NT 6.2; WOW64; 
    rv:28.0) Gecko/20100101 Firefox/28.0)'; }
});

This isn't possible from the page itself.这在页面本身是不可能的。 The user agent string (as sent in the HTTP request headers) can only be changed via browser extension or browser configuration.用户代理字符串(在 HTTP 请求标头中发送)只能通过浏览器扩展或浏览器配置进行更改。

This is now possible to do, see: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name You can use ' XMLHttpRequest.setRequestHeader(User-Agent, value)'现在可以这样做,请参阅: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name您可以使用“XMLHttpRequest.setRequestHeader(User-Agent, value)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改请求标头(用户代理)中的客户端信息? - How to change the client informations in the request header (User-Agent)? 如何解决拒绝在 Javascript 中设置不安全的标头“User-Agent” - how to resolve Refused to set unsafe header "User-Agent" in Javascript 更改 javascript 音频播放器的用户代理 - Change user-agent of javascript audio player 将casperjs的默认浏览器更改为chrome(更改用户代理字符串) - Change the default browser of casperjs to chrome (Change the user-agent string) 谁能帮助您以编程方式使用Selenium Webdriver将修改标头用户代理添加到Chrome浏览器 - Can anyone help to how to add modify header user-agent to chrome browser using selenium webdriver programmatically 如何使用修改的User-Agent标头javascript或php进行跨源Http发布请求? - How to make a cross origin Http post request with modified User-Agent header javascript or php? 如何在javascript中检索用户代理值(未定义代理)? - How to retrieve user-agent value in javascript (Agent is not defined)? 如何用js获取HTTP user-agent header? - How to get HTTP user-agent header with js? jplayer自定义用户代理HTTP标头 - jplayer custom user-agent http header 如何使用 JavaScript 在用户代理影子根中获取元素? - How to get element in user-agent shadow root with JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM