Using JavaScript in HTML

Source: Internet
Author: User
  1. Using <script> elements
  2. embedding scripts and external scripts
  3. Consider browser scenarios that disable JavaScript

Insert JavaScript into the HTML page to use the <script> element. Using this element, you can embed JavaScript into an HTML page and let the script mix with the markup. You can also include external JavaScript files. Where we need to be aware:

  • When you include an external JavaScript file, you must set the SRC attribute to the URL that points to the response file. This file can be either a file located on the same server as the page containing it, or a file in any other domain.
  • All <script> elements are parsed sequentially in the order in which they appear in the page. Without using the defer and async properties, the code in the following <script> elements will be parsed only after the code in the previous <script> element has been parsed.
  • Hesitate the browser will parse the code in the <script> element that does not use the Defer property, and then after parsing the content, the <script> element should be placed at the end of the page, that is, the main content behind the,</body> tag.
  • Use the Defer property to have the script execute after the document is fully rendered. Deferred scripts are always executed in the order in which they are specified.
  • Use the Async property to indicate that the current script does not have to wait for other scripts or block document rendering. There is no guarantee that asynchronous scripts will execute in the order they appear in the page.

In addition, the use of the <noscript> element can specify that a substitute is displayed in a browser that does not support scripting, but if scripting is enabled, the browser does not display any content in the <noscript> element.

Using JavaScript in HTML

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.