简体   繁体   English

在Firefox中更新用户代理

[英]Update User Agent in Firefox

I would like to change my User Agent while browsing and display the changes on a website. 我想在浏览时更改用户代理并在网站上显示所做的更改。 I already got a website that prints the UserAgent, simply using JS document.writeln(navigator.userAgent) . 我已经有一个使用JS document.writeln(navigator.userAgent)来打印UserAgent的网站。

When I load this page with Chrome, it displays my default UA (let's say abc ). 当我使用Chrome加载此页面时,它将显示我的默认UA(假设abc )。 When I change it to xyz and refresh (Ctrl+F5), it displays the new UA xyz . 当我将其更改为xyz并刷新(Ctrl + F5)时,它将显示新的UA xyz Great, that is exactly what I wanted! 太好了,这正是我想要的!

Now if I do the same thing with Firefox, the displayed UA won't update. 现在,如果我使用Firefox做同样的事情,显示的UA将不会更新。 So I load the page with abc as my UA, I change it to xyz , refresh the site (again without cache) but it still displays abc . 因此,我以abc作为UA加载页面,将其更改为xyz ,刷新了站点(再次没有缓存),但仍然显示abc

The Apache logs and Wireshark both show that the UA transported in the HTTP header is actually the new xyz . Apache日志和Wireshark均显示HTTP标头中传输的UA实际上是新的xyz

Does anyone of you have an idea what is happening here? 你们中有人知道这里发生了什么吗?

This is by design. 这是设计使然。 From MDN : MDN

In Firefox, you can change the preference general.useragent.override in about:config. 在Firefox中,您可以在about:config中更改首选项general.useragent.override。 Some Firefox extensions do that; 一些Firefox扩展程序可以做到这一点。 however, this only changes the HTTP header that gets sent, and doesn't affect browser detection performed by JavaScript code. 但是,这只会更改发送的HTTP标头,不会影响JavaScript代码执行的浏览器检测。

As some of you suggested I had read the navigator object, not the actual HTTP header, thanks for that! 正如你们中某些人所建议的那样,我已经阅读了导航器对象,而不是实际的HTTP标头,谢谢!

I solved it using PHP instead: 我改用PHP解决了它:

    <?php
        $header=getallheaders();
        foreach ($header as $name => $value) 
        {
            echo "$name: $value<br/>";
        }
    ?>

Or just 要不就

    <?php
        $header=getallheaders();
        $ua=$header["User-Agent"];
        echo "$ua<br/>";
    ?>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM