Self-Closing Script Elements: A Browser Anomaly
Browsers, notably Microsoft Internet Explorer versions 6 through 8 beta 2, exhibit peculiar behavior when it comes to self-closing script elements (). Unlike the standard form (), these self-closing elements are not recognized as valid script tags by the browser. This inconsistent behavior raises concerns about browser support for XHTML.
Delving into the technical reasoning behind this non-recognition, we turn to the XHTML 1 specification's non-normative appendix 'HTML Compatibility Guidelines.' Specifically, section C.3. Element Minimization and Empty Element Content states:
Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. useand not ).
Examining the XHTML DTD, we find that script elements are defined as:
This definition specifies that script elements must contain PCDATA (parsed character data), indicating that they cannot be empty. Therefore, according to the XHTML Compatibility Guidelines, script elements should not be minimized as but rather expanded as <script></script>.
Browsers, adhering to this guideline, reject self-closing script elements because they lack the expected content. This behavior ensures compliance with the XHTML specification but potentially breaks XHTML support, as authors may use the minimized form unaware of the compatibility issue.
The above is the detailed content of Why Do Some Browsers Reject Self-Closing Script Tags?. For more information, please follow other related articles on the PHP Chinese website!