Compatibility Mode in IE8 using VBScript

≯℡__Kan透↙ 提交于 2019-12-13 16:00:26

问题


Is it possible to set and check the Compatibility Mode in IE8 using VBScript?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/934178/compatibility-mode-in-ie8-using-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!