34

just a little question about this comment I found on an ebook about HTML5: /*@cc_on!@*/0 this comment should be somehow bound to the recognition of the IE browser in order to use the document.createElement() to create the unrecognized HTML5 elements, but I didn't find useful infos about the meaning of how this works cause even the author doesn't explain it. Could someone explain me what it is and what it does, please?

Thanks for the attention!

EDIT:

in the ebook the author says:

The next example demonstrates how to solve the problem for all the new elements introduced in HTML5. Here we include all the elements we’d like to force IE to recognize:

And here is the code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Styling Unknown Elements - 3</title>
    <script>
        (function() {
            if (! /*@cc_on!@*/ 0)
                return;

            var e = "abbr,article,aside,audio,canvas,  datalist,details,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output, progress,section,time,video".split(','),
                i = e.length;
            while (i--) {
                document.createElement(e[i]);

            }
        })()
    </script>
    <style>
        time {
            font-style: italic;
        }
    </style>
      ...

Sorry for the horrible indentation but I am using a tablet. Anyway please take a look at the script tag and at that if condition.

1 Answer 1

41

@cc_on Statement is the conditional compilation flag for IE(< 11) browser

@cc_on Statement (JavaScript)

Activates conditional compilation support within comments in a script.

Caution

Conditional compilation is not supported in Internet Explorer 11 Standards mode and Windows Store apps. Conditional compilation is supported in Internet Explorer 10 Standards mode and in all earlier versions.

/*@cc_on @*/
/*@
    document.write("JavaScript version: " + @_jscript_version + ".");
    document.write("<br />");
    @if (@_win32)
        document.write("Running on the 32-bit version of Windows.");
    @elif (@_win16)
        document.write("Running on the 16-bit version of Windows.");
    @else
        document.write("Running on a different operating system.");
    @end
@*/

so

if(!/*@cc_on!@*/0)

If your browser doesn't know conditional compilation (other than IE < 11), the expression will be:

if(!0) // ==> TRUE

otherwise it will be:

if(!!0) // ==> FALSE
3
  • Thanks for the response, but the conditional compilation statement in my case is a bit different, could you explain me please why there's a !@ after the @cc_on and what is that 0 after the */ comment closure?
    – tonix
    Commented Jun 29, 2014 at 7:44
  • only another question: in the code example you posted all the code within the comment that starts on the line 2, i.e. "/*@" is compiled only by versions of I.E. other than 11, e.g. 8, 7, am I right?
    – tonix
    Commented Jun 29, 2014 at 17:19
  • MSDN link is now broken, FYI Commented Apr 9, 2023 at 14:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.