基于浏览器版本的不同内容?
问题描述:
是否可以根据用户使用的浏览器在CMS(DNN)中显示不同的内容?例如,IF IE 7然后显示内容1基于浏览器版本的不同内容?
IE7并不像图像映射那样好,而只是向用户显示我已经制作的流程图的静态图像。
<!--[if IE 7]>
Special instructions for IE 7 here
<![endif]-->
我想一些代码jQuery来的内容窗格中删除DIV类的内容(即页,所以对于文件扩展名process.aspx检查),然后启用隐藏DIV的图像。 < <那是我的理论吗?
- 检测哪些浏览器(如IE 7则:
- 从内容窗格中删除内容(检查process.aspx的URL)
- 使使用
display:block
隐藏DIV)
答
可以使用jQuery.browser
方法:
if (jQuery.browser.msie && jQuery.browser.version == '7.0') {
$('#content').show();
}
+0
我有'jQuery.browser'方法的一些问题。我最终更喜欢使用基于CSS的浏览器检测。 – sp00m 2012-04-24 10:05:57
答
这里一个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();
}
});
答
老实说,你可能只是这样做的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。
那么,你想检测用户使用JS使用的浏览器,就是这样吗? – sp00m 2012-04-24 09:59:16
在编辑中添加了更多信息。 – 2012-04-24 09:59:45