The function of the page inside CDATA _ Experience Exchange

Source: Internet
Author: User
Tags cdata
The contents of the <script> and <style> elements must be wrapped into a CDATA section.

If you use special characters (such as < or &) or entity references (such as < or &) in a script or style sheet, you will need to mark the contents of the script or style sheet as a CDATA (character data) section, as shown below.

<script type= "Text/javascript" >
<! [cdata[

function Isless (A, b) {
if (a < b)
return true;
}

]]>
</script>

Using a CDATA section is not valid for all browsers. For example, Internet Explorer treats a CDATA section in <script> tags as a syntax error. You can avoid this problem by adding JavaScript annotations, as shown below.

<script type= "Text/javascript" >
/* <! [cdata[* *

function Isless (A, b) {
if (a < b)
return true;
}

*]]> * *
</script>

JavaScript uses/* and */to flag the start and end of annotations. Therefore, the CDATA section hides from JavaScript, but not the browser that analyzes the page. In summary, it's a good idea to put style rules and scripts in an external file and refer to them from the XHTML page. You can avoid all of these problems by using external style sheets and scripts.

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.