Skip to content Skip to sidebar Skip to footer

Can I Detect Ie Document Mode On The Server Side Using The Httpbrowsercapabilities Object

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

Solution 1:

You should be able to use the Request.UserAgent to get the string that has the capability flag in it.

Check these 2 links.

Understanding User-Agent strings

User-Agent Properties

Edit Figured I would add more detail. Basically the Trident token of the User-Agent string is the REAL version of the browser and the MSIE token is the browser mode it is using. You can easily check this out by using the first link and running fiddler to see what the HTTP headers look like.

MORE EDIT I turn on fiddler and browse to www.yahoo.com with IE9.0 and see User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) I then hit the compatibility mode button and see:

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR2.0.50727; .NET CLR3.5.30729; .NET CLR3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7)

See how the trident = 5.0 both times but the MSIE is 9.0 and then 7.0?

Depending on the URL you are going to there are ways to force this information. For instance on the web app I am working right now we force IE7 Compatibility mode because of some various reasons.

Solution 2:

No. you cannot determine the document mode via server side code. You can check the compat. mode with the trident value in the user agent, which defaults the document mode. Key word..DEFAULTS..IT CAN STILL BE CHANGED via F12. If a user then changes the document mode again, to something besides what compat. mode changes it to, then you will not be able to see the change.

Solution 3:

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

<head><scripttype="text/javascript>"...varchoice;
    if (condition) {
        choice = 'ie7';
    } else {
        choice = 'default';
    }
    document.writeln('<linktype="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.

Post a Comment for "Can I Detect Ie Document Mode On The Server Side Using The Httpbrowsercapabilities Object"