Home >Web Front-end >JS Tutorial >Why Don't Some Browsers Recognize Self-Closing Script Tags?
Browser Inconsistencies with Self-Closing Script Elements
In HTML and XHTML, the proper syntax for a script element is:
<script src="foobar.js"></script>
Yet, in browsers like Internet Explorer (6-8 beta 2), self-closing script elements are not recognized:
<script src="foobar.js" />
XHTML Compatibility Concerns
The XHTML 1 specification's appendix on HTML compatibility guidelines explicitly prohibits the use of minimized forms for non-empty elements, such as title and paragraph.
DTD Specification
Furthermore, the XHTML DTD specifies script elements as:
<!ELEMENT script (#PCDATA)>
This indicates that script elements may contain character data but should not be empty.
Conclusion
Therefore, the inconsistency with self-closing script elements is due to the incompatibility of such syntax with the XHTML DTD and HTML compatibility guidelines. Browsers like Internet Explorer prioritize conformance to these standards, leading to the non-recognition of self-closing script elements.
The above is the detailed content of Why Don't Some Browsers Recognize Self-Closing Script Tags?. For more information, please follow other related articles on the PHP Chinese website!