我可以使用HttpBrowserCapabilities对象在服务器端检测IE文档模式吗? [英] Can I detect IE Document Mode on the server side using the HttpBrowserCapabilities object

查看:92
本文介绍了我可以使用HttpBrowserCapabilities对象在服务器端检测IE文档模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用HttpBrowserCapabilities对象找到浏览器的版本和特定功能,但是有没有办法找到浏览器用来呈现的文档模式?

I can find out the browser version and specific capabilities using the HttpBrowserCapabilities object, but is there a way I can find the Document Mode that the browser is using to render?

等效于JavaScript属性document.documentMode

The equivalent of the JavaScript property document.documentMode

可以通过开发人员工具

更新

我希望在razor布局页面中使用类似的样式为IE7及以下版本提供单独的样式表...

I was hoping to include a separate stylesheet for IE7 and below using something like this in my razor layout page...

@if (ViewContext.IsBrowserOlderThanIE8()) {
<link href="Ie7.css" rel="stylesheet" type="text/css" />
}

在功能IsBrowserOlderThanIE8中,我可以检测到浏览器版本,但这不足以了解客户端使用的文档模式.文档模式对实际使用的渲染引擎有更多的限制.

Within function IsBrowserOlderThanIE8 I can detect the browser version, but this is not enough to know what document mode the client is using. The document mode has more baring on the actual rendering engine used.

推荐答案

您可以在客户端确定它,然后让客户端请求正确的css文件...

You can determine it on the client side, then have the client request the correct css file...

<head>
<script type="text/javascript>"
    ...
    var choice;
    if (condition) {
        choice = 'ie7';
    } else {
        choice = 'default';
    }
    document.writeln('<link type="text/css" rel="stylesheet" href="' + choice + '.css" />');
</script>
...
</head>

当然,您可以使这个小的选择器"脚本成为其中包含的文件,而不是实际在您制作的每个页面中对其进行内联编码.

And of course you could make that little "selector" script a file that's included, rather than actually coding it in-line in each page you make.

这篇关于我可以使用HttpBrowserCapabilities对象在服务器端检测IE文档模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆