Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Internet Explorer Found an IE comment bug

    inserting a comment before

    Code:
    <!DOCTYPE html>
    example:

    Code:
    <!-- author me@me.com --><!DOCTYPE html>
    (IE will screw up, thinking you have placed HTML elements above the doctype. So it will not render the css properly. Which comments by rule of code "should" always be ignored for security and organization.)

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,714
    Thanks
    0
    Thanked 238 Times in 233 Posts
    Hi there sitNsmile,

    It is not an IE bug.

    Placing a comment before the dtd always directs IE browsers to render the page in "Quirks Mode".

    Further reading:-

    coothead

  • #3
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by coothead View Post
    Hi there sitNsmile,

    It is not an IE bug.

    Placing a comment before the dtd always directs IE browsers to render the page in "Quirks Mode".

    Further reading:-

    coothead
    hmm okay. Thanks. It was frustrating one night trying to figure why IE wasn't working when other browsers where. But this makes sense. I still think comments should always be ignored.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The reason that isn't a bug is because the doctype has to come first because that's what provides the information that says that what follows is an HTML document.

    If the doctype doesn't come first then the browser assumes it is HTML (as that's the most likely thing a browser expects) but browsers use the doctype as a switch for whether to use standard or quirks mode and so the browser uses quirks mode because the SGML doctype tag is not on the front of the document where it belongs. You then have an invalid second tag in your document because doctype is not a valid HTML tag (at least it wasn't before HTML 5 which proposes adding it as one - but only if it precedes everything else so after the comment would still be an invalid location).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    Quote Originally Posted by felgall View Post
    ... so the browser uses quirks mode because the SGML doctype tag is not on the front of the document where it belongs. You then have an invalid second tag in your document because doctype is not a valid HTML tag ...
    This isn't true. Validate this document with the W3C's SGML-based (for HTML4) validator:

    Code:
    <!-- SGML Comment 1 -- -- SGML Comment Part 2 -->
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" []>
    <title/Demo Document/
    <p>Hello World<input button value="Click Me!"</html>
    It passes with flying colors.

    Quote Originally Posted by coothead View Post
    It is not an IE bug.
    I believe this started out as a bug; this behavior wasn't mentioned in the IE6 "enhancements" list where quirks mode was first introduced: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx. Yet, the behavior remains in IE9, so it's presumably a "feature" at this point.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The W3C validator only validates some of the standard - it does not validate everything. Also web browsers don't understand SGML, they only understand HTML and so passing the SGML validator doesn't mean it will work as a web page. HTML 1 and HTML 5 don't even follow the SGML standards in how they are defined and so would not need to pass SGML validation. While HTML 2, 3.2 and 4 are defined using SGML the browsers do not use those SGML definitions (unfortunately).

    Another example of something in the standard it doesn't validate (this time using the HTML validator that you would expect to apply to web pages) is that you don't nest <input> tags directly inside <form> tags. The <input> needs to be in a block tag of some sort that is itself inside the <form>. <input> tags are invalid outside of forms but because the validator only checks that it is inside a block tag and doesn't check that the block it is in is inside a form the validator will not complain about input tags outside of forms even though they are invalid.

    Since an HTML document starts with a <html> tag (apart from HTML 5 which has added an extra tag to put in front of that to substitute for the part of the SGML tag that the browsers expect to see) you can't validly place a comment outside of that regardless of whether the validator actually detects the error or not. In fact since the only tags allowed inside a <html> tag are <head> and <body> presumably comments only need to be treated as valid when inside one of those two tags. Admittedly each of those three tags is optional and so if your page omits the html, head, and body tags then a comment could be the first HTML tag but that still can't come before the optional SGML tag that defines the document as HTML as the first HTML tag the page contains will define the rest of the page as HTML and then the <!doctype> tag is invalid because it isn't an HTML tag (prior to the proposal to introduce it as one in HTML 5 because HTML 5 isn't following the SGML document markup definition standard but is doing its own thing instead).

    In this instance it is a failure of the validator to detect an invalid tag placement and what IE is doing is perfectly in accordance with the standard as per its SGML definition. Other browsers just the invalidly placed tag and you only get away with it because the comment is supposed to be ignored.
    Last edited by felgall; 01-25-2012 at 09:53 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    Quote Originally Posted by felgall View Post
    The W3C validator only validates some of the standard - it does not validate everything.
    It validates according to the SGML syntax and DTD constraints which is enough to disprove your claim that putting a document type declaration after a comment causes it to be interpreted as an element in an illegal context.

    Quote Originally Posted by felgall View Post
    Also web browsers don't understand SGML, they only understand HTML and so passing the SGML validator doesn't mean it will work as a web page.
    I never said it would. All of that SGML sugar in my example code was just to demonstrate that the validator was in fact processing the code as SGML.

    Quote Originally Posted by felgall View Post
    HTML 1 and HTML 5 don't even follow the SGML standards in how they are defined and so would not need to pass SGML validation.
    HTML5 uses conformance-based validation. Validators are not restricted to the limited feature set of a DTD. Instead, you have a testable set of criteria and if one is not met, then you have an error or warning.

    Quote Originally Posted by felgall View Post
    Another example of something in the standard it doesn't validate (this time using the HTML validator that you would expect to apply to web pages) is that you don't nest <input> tags directly inside <form> tags. The <input> needs to be in a block tag of some sort that is itself inside the <form>. <input> tags are invalid outside of forms but because the validator only checks that it is inside a block tag and doesn't check that the block it is in is inside a form the validator will not complain about input tags outside of forms even though they are invalid.
    "The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces." —http://www.w3.org/TR/html401/interac...#form-controls

    felgall, please load the spec in your browser and put it on your bookmarks list.

    Quote Originally Posted by felgall View Post
    Since an HTML document starts with a <html> tag ... you can't validly place a comment outside of that regardless of whether the validator actually detects the error or not.
    According to what? Could you please provide me a link showing where that's specified or an SGML guide that affirms that? Or even a quote from a book that you have?

    Quote Originally Posted by felgall View Post
    what IE is doing is perfectly in accordance with the standard as per its SGML definition.
    Please guide me to this "SGML definition." I can't seem to find it for some reason.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •