Home > Web Front-end > JS Tutorial > Why Don't Some Browsers Recognize Self-Closing Script Tags?

Why Don't Some Browsers Recognize Self-Closing Script Tags?

Barbara Streisand
Release: 2024-12-18 00:39:09
Original
242 people have browsed it

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:

1

<script src="foobar.js"></script>

Copy after login

Yet, in browsers like Internet Explorer (6-8 beta 2), self-closing script elements are not recognized:

1

<script src="foobar.js" />

Copy after login

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:

1

<!ELEMENT script (#PCDATA)>

Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template