htmlinternet-explorertypo3conditional-comments

Exclude part for all IE-versions in typo3


I would like to temporary exclude all version of the Internet Explorer (IE) from a specific part in my typo3 html file. I tried to comment it out this way:

<!--[if !IE]> -->
<p>Some content here</p>
<!-- <![endif]-->

This method does not work.

Does anyone has a solution for this problem?


Solution

  • The Conditional comments (<!--[if !IE]> -->) have been removed in Internet Explorer 10, so, it only works before IE9 version.

    To detect all IE versions using JavaScript, I suggest you could check the userAgent string. Under the IE 9 version, you could use the conditional comments to control the comments, for IE 9+ version, you could use JavaScript to hide the comments.

    Please check the following sample:

    <!--[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>