[英]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.