JavaScript CSS: Proper use of CSS and JavaScript in XHTML documents

Source: Internet
Author: User
Tags cdata contains

Proper use of CSS and JavaScript in XHTML documents
Xhtml? 1.0 The Extensible Hypertext Markup Language (Second Edition) defines XHTML as an application that extends HTML 4 to imaging XML 1.0.
XHTML is rapidly replacing HTML 4 in many sites, however, mainstream browsers are not doing enough to fully support XHTML, and web designers lack understanding of the fundamental differences between HTML 4 and XHTML, creating a growing problem on the web today.
XHTML is XML, not HTML
One of the main misconceptions about XHTML is that it's just another version of HTML. The misconception arises from the fact that Microsoft? Internet Explorer supports XHTML only when files are committed in MIME type text/html, whereas the recommended type in the standard is actually application/xhtml+xml.
When the MIME type of an XHTML page is submitted as text/html, it is treated as HTML by all browsers, as if XHTML is no different than HTML. However, when the MIME type of an XHTML page is submitted as Text/xml or application/xhtml+xml, it is treated as an XML document, and the design and presentation of XML are subject to strict rules.
True XHTML is an application of XML, so strict rules are also adhered to when creating XHTML. Especially:
Unhandled < and & not allowed in CDATA regions (<! cdata...>).
The annotation (<!—— ... —— >) cannot contain a double horizontal line.
The content contained in the comment (<!—— ... —— >) is ignored.
Problems in inline style and script
inline style and script tags can create several different problems when treated as XML instead of HTML.
JavaScript contains some characters that are not allowed in XHTML
Typical JavaScript contains special characters that are not allowed to be placed outside of the CDATA area in XHTML.
<script type= "Text/javascript" > var i = 0; while (++i < 10) {//...} </script> Note This example is not XHTML written in the correct format because it uses an unprocessed "<" that can only appear when it is part of an XHTML or XML tag.
Using annotations in inline style and script
Designers who are familiar with HTML often put inline style and script content in comments so that they can be hidden in browsers that do not support styles and scripts.
<style type= "Text/css" > <!--body {background-color:blue; color:yellow;}--></style><script type  = "Text/javascript" > <!--var i = 0;   var sum = 0;  for (i = 0; i < ++i) {sum = i; Alert (' sum = ' + sum '); --></script> This example illustrates that a particular browser can ignore the contents of a comment. In addition, this example also shows that different browsers are dealing with text/xml or
The different problems that arise when application/xhtml+xml content.
Mozilla 1.1+/opera 7
You cannot use CSS, and you cannot execute JavaScript.
Netscape 7.0x/mozilla 1.0.x
You cannot use CSS, but you can do JavaScript.
Internet Explorer 5.5+
The document cannot be displayed properly.
inline style and script that contain double horizontal lines
Another problem with JavaScript being included in annotations in XHTML files is the same problem as using a double line in an XHTML annotation.
<script type= "Text/javascript" ><!--var i;  var sum = 0;  for (i = i > 0; i.) {sum = i; }//--></script> use CDATA Instead of annotations for this article link http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20130902/40008.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.