2014-02-24 44 views
0

我正在建立一個網站,我想包括基於document mode瀏覽器在(不是browser mode)的我的樣式表的不同版本。基於IE文檔模式的加載CSS樣式表

例如,documentmode = ie8的我可能要加載main_ie8.css但如果documentmode = ie9我可能要加載main_ie9.css

我有一個數字,在兼容模式下運行IE9的用戶。這默認document mode爲ie7標準。我用下面的meta標籤,迫使document mode到IE9標準IE9:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 

問題是browser mode仍設置爲IE的兼容性。所以用戶代理仍然設置爲IE7。

既然沒有辦法在服務器端,以確定document mode瀏覽器中運行,並且有條件的意見也是基於browser mode不是document mode,我怎麼可以基於document mode而非browser mode載入我的css文件。

+1

http://conditionizr.com/ –

+0

對於你IE8文件模式還是隻有IE8有什麼區別? –

+0

不確定你在問什麼。我不認爲IE8中的IE8文檔模式和IE9中的IE8文檔模式有什麼不同。我可能是錯的,但我相信這兩個頁面應該呈現相同的情況? – kralco626

回答

0

使用此代碼來檢測瀏覽器模式和文檔模式。

var j = jQuery.noConflict(); 
j(document).ready(function(){ 
    /* detect usage of IE Developer Tools using different Mode for Browser and Document */ 
    if(j.browser.msie) { 
     var browserVersion = j.browser.version.slice(0,j.browser.version.indexOf(".")); 
     var documentVersion = document.documentMode; 
     } 
    } 
}); 

發送AJAX '得到' 打電話到sample.php腳本:

  if (window.XMLHttpRequest) 
      { 
       xmlhttp=new XMLHttpRequest(); 
      } 
      else 
      { 
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      xmlhttp.onreadystatechange=function() 
      { 
       if (xmlhttp.readyState==4 && xmlhttp.status==200) 
       { 
        //do the settings based on the response from php 
        /*you can echo the css file name to be picked 

based 
on browser mode or document mode*/ 
         var response=xmlhttp.responseText; 
        } 
       } 


xmlhttp.open("GET","http://<?php echo IP; ?>/yourapp/sample.php?mode="+,true); 
      xmlhttp.send(); 

希望它能幫助!

0

你可以運行一個測試文檔模式的條件javascript,然後附加css。喜歡的東西:

if (BrowserDetect.browser == 'Explorer') 
{ 
    if (document.documentMode == 7 && BrowserDetect.version > 7) 
    { 
     // user is running IE in compatability mode 
     // load special CSS 
    } 
} 

https://stackoverflow.com/a/13732003/3100667

如果這是更多的CSS樣式,它聽起來像瀏覽器支持的問題得到了類似的帖子回答這個想法,你也可以解決它通過加載墊片和polyfill以在舊版IE中支持CSS3支持。流行的HTML5 Shiv是一個很好的起點。

其他polyfills的集合,可以幫助修復你針對一個特定的問題是在https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

0

您可以嘗試有條件的意見

http://www.quirksmode.org/css/condcom.html

<p class="accent"> 
<!--[if IE]> 
According to the conditional comment this is IE<br /> 
<![endif]--> 
<!--[if IE 6]> 
According to the conditional comment this is IE 6<br /> 
<![endif]--> 
<!--[if IE 7]> 
According to the conditional comment this is IE 7<br /> 
<![endif]--> 
<!--[if IE 8]> 
According to the conditional comment this is IE 8<br /> 
<![endif]--> 
<!--[if IE 9]> 
According to the conditional comment this is IE 9<br /> 
<![endif]--> 
<!--[if gte IE 8]> 
According to the conditional comment this is IE 8 or higher<br /> 
<![endif]--> 
<!--[if lt IE 9]> 
According to the conditional comment this is IE lower than 9<br /> 
<![endif]--> 
<!--[if lte IE 7]> 
According to the conditional comment this is IE lower or equal to 7<br /> 
<![endif]--> 
<!--[if gt IE 6]> 
According to the conditional comment this is IE greater than 6<br /> 
<![endif]--> 
<!--[if !IE]> --> 
According to the conditional comment this is not IE 5-9<br /> 
<!-- <![endif]--> 
</p>