IE开发工具文档模式用户代理

时间:2014-06-17 20:01:24

标签: internet-explorer internet-explorer-11

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

这是IE开发工具中的错误吗?如果没有,那么让IE将适当的User-Agent标头发送到远程服务器的正确方法是什么?

1 个答案:

答案 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.
  

唐' T:

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.

<强>参考