2014-06-17 17 views
0

将文档模式设置为默认值以外的值不会在请求中发送相应的User-Agent标头(如在IE devtools的网络选项卡中所见)。但是,在控制台中执行navigator.userAgent确实反映了适当的字符串(与文档模式/用户代理设置关联)。IE开发工具文档模式用户代理

这是IE开发工具中的一个bug吗?如果不是,那么让IE将相应的User-Agent标头发送到远程服务器的正确方法是什么?

+0

我期待它的工作相应:) – culturalanomoly

+0

第一个错误,这是IE浏览器,它从未相应的工作原理:d 但在所有的严重性,如果你想要测试不同版本的IE 使用一个名为IETester的程序 – MarshallOfSound

+0

您是否只设置了“文档模式”?或者您是否设置了“文档模式”和“用户代理字符串”值? 为了更改发送到服务器的用户代理报头请求,您必须更改“用户代理字符串”值 –

回答

0

在JavaScript中,document.documentMode映射到F12开发人员工具。用户代理不受影响:

务必:

使用以下几种检测方法更可靠地检测误差的来源,并确保您的网页在不同浏览器兼容:

Feature detection: Test whether a browser supports a feature before you use it. Feature detection enables cross-browser code to "just work" without requiring you to know the capabilities of every browser ahead of time. For example, the jQuery framework relies almost entirely on feature detection. For more info about how you can use jQuery's feature detection in your own site, see the jQuery.support documentation. 
Behavior detection: Test for known issues before you apply a workaround. jQuery also uses behavior detection by running tests for known issues to determine if certain workarounds are needed. 

不要:

Detect specific browsers: Don't use the identity of a browser (for example, navigator.userAgent) to change a page's behavior. If you change code based on a specific browser, the page cannot easily adapt to changes and it might break when a new browser is released. In other situations, pages use a legacy workaround even when that workaround is no longer needed. 
Assume unrelated features: Don't perform feature detection for one feature and then use a different feature. Sites that have this problem perform feature detection for one feature and then use other features without testing whether they are supported. 

参考

相关问题