【问题标题】:Exclude part for all IE-versions in typo3在typo3中排除所有IE版本的部分
【发布时间】:2020-04-20 10:07:57
【问题描述】:
我想暂时从我的typo3 html 文件的特定部分中排除所有版本的 Internet Explorer (IE)。
我试着用这种方式评论它:
<!--[if !IE]> -->
<p>Some content here</p>
<!-- <![endif]-->
此方法无效。
有人有解决这个问题的办法吗?
【问题讨论】:
标签:
html
internet-explorer
typo3
conditional-comments
【解决方案1】:
Conditional comments (<!--[if !IE]> -->) 已在 Internet Explorer 10 中删除,因此它仅适用于 IE9 版本之前。
要检测所有使用 JavaScript 的 IE 版本,我建议您检查 userAgent 字符串。在 IE 9 版本下,可以使用条件 cmets 来控制 cmets,对于 IE 9+ 版本,可以使用 JavaScript 隐藏 cmets。
请检查以下示例:
<!--[if !IE]> -->
<p id="iecontent">Some IE content here</p>
<!-- <![endif]-->
<script>
//userAgent in IE7 WinXP returns: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
//userAgent in IE11 Win7 returns: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
if (navigator.userAgent.indexOf('MSIE') != -1)
var detectIEregexp = /MSIE (\d+\.\d+);/ //test for MSIE x.x
else // if no "MSIE" string in userAgent
var detectIEregexp = /Trident.*rv[ :]*(\d+\.\d+)/ //test for rv:x.x or rv x.x where Trident string exists
if (detectIEregexp.test(navigator.userAgent)) { //if some form of IE
var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
//define a flag to check whether IE version is IE 9+
var flag = false;
if (ieversion >= 12)
{
document.write("You're using IE12 or above");
flag = true;
}
else if (ieversion >= 11)
{
document.write("You're using IE11 or above")
flag = true;
}
else if (ieversion >= 10)
{
document.write("You're using IE10 or above")
flag = true;
}
else if (ieversion >= 9)
document.write("You're using IE9 or above")
else if (ieversion >= 8)
document.write("You're using IE8 or above")
else if (ieversion >= 7)
document.write("You're using IE7.x")
else if (ieversion >= 6)
document.write("You're using IE6.x")
else if (ieversion >= 5)
document.write("You're using IE5.x")
if (flag)
document.getElementById("iecontent").style.display = "none";
}
else {
document.write("n/a")
}
</script>