Conditional Comment Query

Discussion in 'HTML' started by KiwiBrian, Oct 26, 2007.

  1. KiwiBrian

    KiwiBrian Guest

    I am running XP SP2 on a Windows PC and running the following test code.
    It does not display the appropriate line of print when I run it under IE7.
    It behaves as expected when I run it under Firefox.
    Can anyone please explain this, and or advise where I am going wrong?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>blah</title>
    <style type="text/css">
    <!--
    body {
    margin: 0;
    padding: 0;
    }
    -->
    </style>
    </head>
    <body>
    <!-- [if IE7]>
    <p style="font-size:24px; color:red">This is an IE test</p>
    <![endif]-->
    <![if !IE]>
    <p style="font-size:24px; color:red">This is a non-IE test</p>
    <![endif]>
    </body>
    </html>

    TIA
    Brian Tozer
    KiwiBrian, Oct 26, 2007
    #1
    1. Advertising

  2. KiwiBrian

    Neredbojias Guest

    Well bust mah britches and call me cheeky, on Thu, 25 Oct 2007 23:35:39
    GMT KiwiBrian scribed:

    > I am running XP SP2 on a Windows PC and running the following test
    > code. It does not display the appropriate line of print when I run it
    > under IE7. It behaves as expected when I run it under Firefox.
    > Can anyone please explain this, and or advise where I am going wrong?
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    > "http://www.w3.org/TR/html4/strict.dtd">
    > <html>
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    > <title>blah</title>
    > <style type="text/css">
    > <!--
    > body {
    > margin: 0;
    > padding: 0;
    > }
    > -->
    > </style>
    > </head>
    > <body>
    > <!-- [if IE7]>
    > <p style="font-size:24px; color:red">This is an IE test</p>
    > <![endif]-->
    > <![if !IE]>
    > <p style="font-size:24px; color:red">This is a non-IE test</p>
    > <![endif]>
    > </body>
    > </html>
    >
    > TIA
    > Brian Tozer


    It should be [if IE 7]. (You have no space.)

    --
    Neredbojias
    Just a boogar in the proboscis of life.
    Neredbojias, Oct 26, 2007
    #2
    1. Advertising

  3. KiwiBrian wrote:
    > I am running XP SP2 on a Windows PC and running the following test code.
    > It does not display the appropriate line of print when I run it under IE7.
    > It behaves as expected when I run it under Firefox.
    > Can anyone please explain this, and or advise where I am going wrong?
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    > "http://www.w3.org/TR/html4/strict.dtd">
    > <html>
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    > <title>blah</title>
    > <style type="text/css">
    > <!--


    Don't need to HTML comment out your CSS, nobody is using a browser that old.

    > body {
    > margin: 0;
    > padding: 0;
    > }
    > -->
    > </style>
    > </head>
    > <body>
    > <!-- [if IE7]>
    > <p style="font-size:24px; color:red">This is an IE test</p>
    > <![endif]-->


    below code isn't it missing the "--" <!--[if !IE]>

    And also since *only* IE recognizes the conventional crap the test "!IE"
    would not be displayed by *any* browser! IE would recognize it and
    evaluate it as false and other browsers will just ignore it an HTML comment.

    > <![if !IE]>
    > <p style="font-size:24px; color:red">This is a non-IE test</p>
    > <![endif]>
    > </body>
    > </html>
    >


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Oct 26, 2007
    #3
  4. KiwiBrian

    BootNic Guest

    "KiwiBrian" <> wrote:
    news:ffr98n$dga$:

    > KiwiBrian wrote:

    [snip]
    >> It behaves as expected when I run it under Firefox.
    >> Can anyone please explain this, and or advise where I am going wrong?

    [snip]
    >> <!-- [if IE7]>


    As it has already be said, you need a space between IE and 7.
    There is also a space before the [ that needs to be removed.

    <!--[if IE 7]>

    [snip]
    > below code isn't it missing the "--" <!--[if !IE]>


    No its not missing anything for HTML.

    > And also since *only* IE recognizes the conventional crap the test
    > "!IE" would not be displayed by *any* browser! IE would recognize > it

    and evaluate it as false and other browsers will just ignore it > an HTML
    comment.

    It is true that conditional comments are for IE, other browsers do not need
    to understand them. If not IE then IE will not display it.

    Other browsers should ignore the conditional comments, and when done
    correctly !IE will display in browsers that are not IE. As the OP has
    stated, it displays as expected in Firefox.

    It is completely incorrect to say that !IE conditional comments will not
    display in any browser, when done correctly.

    >> <![if !IE]>
    >> <p style="font-size:24px; color:red">This is a non-IE test</p>
    >> <![endif]>


    Another option for the !IE comment would be:

    <!--[if !IE]> <-->
    <p style="font-size:24px; color:red">This is a non-IE test</p>
    <!--> <![endif]-->

    [snip]

    http://msdn2.microsoft.com/en-us/library/ms537512.aspx

    --
    BootNic Friday October 26, 2007 1:47 AM
    Thirty-five is when you finally get your head together and your body
    starts falling apart.
    *Caryn Leschen*
    BootNic, Oct 26, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alec S.
    Replies:
    10
    Views:
    10,091
    Alec S.
    Apr 16, 2005
  2. patrick j
    Replies:
    6
    Views:
    396
    patrick j
    Oct 25, 2006
  3. andrew
    Replies:
    61
    Views:
    2,016
    André Gillibert
    Dec 11, 2007
  4. John
    Replies:
    2
    Views:
    415
  5. Guy Hocking

    ASP / SQL Query - Conditional SELECT Statement

    Guy Hocking, Jan 21, 2004, in forum: ASP General
    Replies:
    7
    Views:
    194
    Bob Barrows
    Jan 21, 2004
Loading...

Share This Page