...

View Full Version : Found an IE comment bug



sitNsmile
01-24-2012, 08:47 AM
inserting a comment before


<!DOCTYPE html>

example:


<!-- 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.)

coothead
01-24-2012, 09:24 AM
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:-
Quirks Mode (http://www.quirksmode.org/css/quirksmode.html)
coothead

sitNsmile
01-24-2012, 10:35 AM
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:-
Quirks Mode (http://www.quirksmode.org/css/quirksmode.html)
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.

felgall
01-24-2012, 07:11 PM
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).

Arbitrator
01-25-2012, 09:32 AM
... 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:


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


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/library/ie/bb250395(v=vs.85).aspx. Yet, the behavior remains in IE9, so it's presumably a "feature" at this point.

felgall
01-25-2012, 10:49 AM
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.

Arbitrator
01-25-2012, 11:21 AM
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.


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.


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.


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/interact/forms.html#form-controls

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


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?


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum