JS Advanced Programming Third Edition--using JavaScript in HTML

Source: Internet
Author: User
Tags cdata

  Ways to use <script> elements

External reference, inline, inline.

  Why JavaScript references are placed behind <body>

If you include all JavaScript files in the

  The use of JavaScript in XHTML

XHTML is an extensible Hypertext Markup language, a standard that is redefined as an application of HTML as XML. The rules for writing XHTML code are much stricter than writing HTML, and directly affect the ability to use <script> tags when embedding javascript code. The following code block is valid in HTML, but is not valid in XHTML because the less than sign (<) in XHTML is interpreted as starting a new label, and as a label, the less than sign cannot be followed by a space.

Workaround One: Replace all the less-than numbers in the code with the corresponding HTML entities (&lt;)

Workaround Two: Use a CDATA fragment to contain the JavaScript code. In XHTML, CDATA fragments are a special area in a document that can contain text content in any format that you do not need to parse.

  HTML Document Mode

By using the document type DOCTYPE, there are currently three document modes: Promiscuous mode, Standard mode, and quasi-standard mode.

 Delay script

HTML defines the defer property for the <script> tag. The purpose of this property is to indicate that the script executes without affecting the construction of the page. In other words, the script is deferred until the entire page has been parsed and then run. Therefore, setting the Defer property in the <script> element is equivalent to telling the browser to download it immediately, but defer execution.

  Asynchronous script

HTML5 defines the async attribute for the <script> element. This property is similar to the defer property and is used to change the behavior of the processing script. Similarly to defer, Async applies only to external script files and tells the browser to download the file immediately. Unlike defer, however, scripts marked as Async are not guaranteed to be executed in the order in which they are specified.

  <noscript> elements

You can specify alternative content that is displayed in browsers that do not support scripting. However, when scripting is enabled, the browser does not display anything in the <noscript> element.

  Extension: Hack technology

Due to different browsers, the parsing of CSS is not the same, so it will result in the resulting page effect is not the same, not get the page effect we need. At this time, we need to write different CSS for different browsers, so that it can be compatible with different browsers, can also be in different browsers to get the desired page effect. The process of writing different CSS code for different browsers is called CSS hack, also called CSS hack.

JS Advanced Programming Third Edition--using JavaScript in 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.