星期四, 11月 29, 2012

[Javascript] 檢查IE Document Mode

客戶遇到ie無法正確指定文件模式的問題。 只要在ui加上<meta http-equiv="X-UA-Compatible" content="IE=edge">,即可。 不過要避免在它之前有其他script執行(網民建議)。 不過今天在客戶那邊處理的時候,之前把content內多加了一個IE=edge,chrome=1,會導致無法正確告訴ie使用最新的文件模式檢視(content)。 以下的語法可以偵測目前用戶的文件模式。
function checkIEDocumentMode(){
 
 if (window.navigator.appName == "Microsoft Internet Explorer")
 {
    if (document.documentMode){
     USERAGENT = document.documentMode;
    } // IE8
    else // IE 5-7
    {
     USERAGENT = 5; // Assume quirks mode unless proven otherwise
       if (document.compatMode)
       {
          if (document.compatMode == "CSS1Compat")
           USERAGENT = 7; // standards mode
       }
    }
    // the USERAGENT variable now contains the document compatibility mode.
    $.console("checkIEDocumentMode:" + USERAGENT);
    //var $metaTag = $("");
    //$metaTag.appendTo("head");
    //content="IE=Value" value types:5、6、7、8、9、10、EmulateIE7、EmulateIE8、Edge
 }
}

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails