-1

是否可以根據用戶使用的瀏覽器在CMS(DNN)中顯示不同的內容?例如,IF IE 7然後顯示內容1基於瀏覽器版本的不同內容?

IE7並不像圖像映射那樣好,而只是向用戶顯示我已經制作的流程圖的靜態圖像。

<!--[if IE 7]> 
Special instructions for IE 7 here 
<![endif]--> 

我想一些代碼jQuery來的內容窗格中刪除DIV類的內容(即頁,所以對於文件擴展名process.aspx檢查),然後啓用隱藏DIV的圖像。 < <那是我的理論嗎?

  1. 檢測哪些瀏覽器(如IE 7則:
  2. 從內容窗格中刪除內容(檢查process.aspx的URL)
  3. 使使用display:block隱藏DIV)
+0

那麼,你想檢測用戶使用JS使用的瀏覽器,就是這樣嗎? – sp00m 2012-04-24 09:59:16

+0

在編輯中添加了更多信息。 – 2012-04-24 09:59:45

回答

1

可以使用jQuery.browser方法:

if (jQuery.browser.msie && jQuery.browser.version == '7.0') { 
     $('#content').show(); 
} 

http://api.jquery.com/jQuery.browser/

+0

我有'jQuery.browser'方法的一些問題。我最終更喜歡使用基於CSS的瀏覽器檢測。 – sp00m 2012-04-24 10:05:57

1

這裏一個JS方法來獲得IE版本(返回-1如果不是IE):

function isUndefined(e) { 
    return typeof e === "undefined"; 
} 

function getIEVersion() { 
    var style = document.body.style; 
    var version = -1; 
    if(!isUndefined(style.scrollbar3dLightColor)) { 
     if (!isUndefined(style.opacity)) version = 9; 
     else if (!isUndefined(style.msBlockProgression)) version = 8; 
     else if (!isUndefined(style.msInterpolationMode)) version = 7; 
     else if (!isUndefined(style.textOverflow)) version = 6; 
     else version = 5; 
    } 
    return version; 
} 

然後,使用jQuery:

$(function() { 
    if(getIEVersion() == 7) { 
     $('#content-pane').hide(); 
     $('#hidden-div').show(); 
    } 
}); 
0

老實說,你可能只是這樣做的CSS。

你有兩個部分內容

<div class="ForEveryone"> 
<!-- Your stuff here --> 
</div> 

<div class="ForIE7"> 
<!-- Code for less helpful browser here --> 
</div> 

則默認情況下已CSS做

.ForIE7 { display: none; } 
與IE 7的具體樣式表變化

然後是

.ForEveryone { display: none; } 
.ForIE7 { display: block; } 

沒有必要去爲這一個JavaScript。