-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。