Is it possible to set and check the Compatibility Mode in IE8 using VBScript?
As per the Defining Document Compatibility article, there's the document.documentMode property that returns the compatibility mode of the current page in IE8. For example, you can type this into the IE8's Address bar to get the compatibility mode value displayed in a message box:
vbscript:msgbox(document.documentMode)
As for modifying the compatibility mode dynamically... You could probably iterate through all meta tags and change the content of the X-UA-Compatible http-equiv header, like in the following example, but I don't have IE 8 so can't say if it actually works.
Sub ChangeCompatMode
Dim metatags, meta
Set metatags = document.getElementsByTagName("meta")
For Each meta In metatags
If UCase(meta.getAttribute("httpEquiv")) = "X-UA-COMPATIBLE" Then
' Change the document mode
meta.setAttribute "content", "IE=edge"
Exit For
End If
Next
End Sub
For the "setting" part... since you control the code delivered to the browser, you control what mode it goes into.
If you want proper standards support, set a valid DOCTYPE and you are set. If you want you can also set the META or HTTP Header to force standards mode so that the end user can't accidentally shoot themselves in the foot by setting it to compatibility mode.
On the other hand, if you have a legacy site that requires IE's legacy rendering/scripting behaviors, then send the META / HTTP Header to force compatibility mode.
Attempting to change this on the fly... is asking for trouble.