Moon JavaScript Introduction Chapter 1th and using JavaScript in HTML Chapter 2nd

Source: Internet
Author: User
Tags blank page hosting

JavaScript basics

JavaScript is a scripting language

is a lightweight programming language.

is a programmatic code that can be inserted into an HTML page.

After inserting an HTML page, it can be performed by all modern browsers.

JavaScript consists of 3 different non-seals: core (ECMAScript)

Document Object Model (DOM)

Browser object Model (BOM)

1. 1 ECMAScript: Defines the JavaScript Foundation. Web browser is just one of the hosting environments implemented by ECMAScript (hosting environment)

Component: A syntax B type C statement d keyword e reserved word f operator G object

Ecma:european Computer Manufacturers Association European Computer Manufacturers Association

ECMAScript protocol standard established by Technical Committee No. 39th (Tc39,technical committee#39)

1. 2 dom:document Object Model is an application interface for XML but expanded for HTML (api,application programming Interface)

The DOM maps the entire page into a hierarchical node structure, and each component of an HTML or XML page is a node of some kind that contains a

Different types of data.

World Wide Web Consortium, www Alliance: Responsible for developing communication standards, start planning the DOM

DOM Level: DOM1 consists of two modules A,dom core (DOM Core) and Dom HTML

Dom Core: Map an XML-based document structure to simplify access and manipulation of any part of the document
The DOM HTML module expands on the DOM core, adding objects and ideas that are positive to HTML

DOM2: Introducing DOM to the DOM1 base (DOM views): Defines an interface that tracks the attempts of different documents.

DOM Event (DOM events): An interface that defines event and event handling.

Dom Style (DOM traversal and Range):

Defines the interface for traversing and manipulating trees.

DOM3: Dom loading and saving based on DOM2 (DOM load and save): Introducing the way interfaces load and save documents in a uniform manner

Dom validation (DOM validation): An interface that defines methods for validating documents

The expansion of the DOM core

1. 3bom:browser object model. Supports the ability to access and manipulate browser window browser object models (where window objects and navigator objects)

Fundamentally, the BOM only handles browsers and windows and frames, and it's customary to say that all JavaScript extensions for browsers count as part of the BOM (see below)

Features of pop-up browser window

The ability to move, zoom, and close the browser window

Navigator object that provides browser details

Location object that provides detailed information about the page loaded by the browser

Screen object that provides detailed information about the user's display resolution

Support for Cookies

Support for custom objects such as the activexobject of XMLHttpRequest and IE

------------------------------------------------------------------------------

Using JavaScript in HTML

Main content of this chapter:

Embed code with external files

Document mode

2. 1

Property:

Async: Optional attribute that indicates that the script should be downloaded immediately, but does not interfere with other actions on the page, such as downloading additional resources or waiting for other scripts to be loaded

Note that it is only useful for external script files

CharSet: Optional attribute that represents the code character set specified by the SRC attribute. Most browsers ignore this property value. Therefore, this property is basically not

Defer: Optional. Indicates that the script can be deferred until the document is fully parsed and displayed before executing

Note that only valid for external script files

SRC: Optional. Represents the external file that contains the code to execute

External JavaScript

You can also save the script to an external file. External files typically contain code that is used by multiple Web pages.

The file name extension for external JavaScript files is. js.

To use an external file, set the. js file in the "src" attribute of the <script> tag:

External scripts cannot contain <script> tags. "On the website of Web site learning"

Type: optional, which represents the content type (also known as MIME type) that writes code using the scripting language. In fact, the server is transmitting JavaScript

Files that are used by MIME types are usually application/x-javascript, in type Setting this value

The Application/x-javascript script ignores that the value of type is used most

Text/javascript, this value is not required for many browsers the default value is Text/javascript

There are two ways to use the

Include external JavaScript files

21.1.1 the location of the

Traditionally, all

Purpose: To place references to all external files (including CSS and JavaScript files) in the same location

The JavaScript file included in the document element means that you must wait until all JavaScript code is downloaded,

After parsing, and execution completes, the page content can be rendered (the browser starts rendering the content when it encounters the tag) for those that require a lot of javascript

The page of the code causes a noticeable delay in rendering the page (the browser window is blank during the delay)

So modern Web applications say all JavaScript references are placed behind the page content in the element "parsing JS code

Before, the page content will be rendered in the browser. Users will feel the speed of opening the page by shortening the blank page of the browser window "

Note Do not appear inside the This means that the end tag will be an error. If you need to use the escape character "\"

Example: alert{"<\/script>"}

If the

Note: does not conform to HTML

The specification does not parse correctly

External JavaScript files are provided with the. JS expansion name. But not necessary,

The , if it contains

The embedded code is ignored and only the external script file is executed

The SRC attribute can be a complete URL to a domain that is outside the HTML page.

Src= "Http://www/somewhere. Com/afile/js ">

Code that is located in the external domain is loaded and parsed as if the code were in the page where they were loaded, and using this to provide JavaScript through different domains when necessary

file, but be careful, either you are the owner of the domain, or the trust of the owner value of that domain

The browser will parse them sequentially according to the order in which the

After the

21.2 Delay Script

The defer property of the

After running the defer property pretty much tells the browser to download it now, but defer execution

Ideal: Multiple deferred scripts are executed in the order in which they appear, that is, the first deferred script takes precedence over the second deferred script execution, and the two

The deferred script takes precedence over the domcontentloaded event,

Reality: Execution of multiple deferred scripts is not sequential or does not necessarily trigger money execution in domcontentloaded events

Therefore, it is best to include only one delay script

Note the Defer property applies only to external script files, and HTML5 explicitly specifies

21.3 Asynchronous scripts

The Async property is similar to a deferred script and tells the browser to download the file immediately.

Differences: Async scripts are not guaranteed to be executed in the order in which they are specified, so it is important that the scripts do not depend on each other.

Use async Purpose: To not allow the page to wait for two scripts to download and execute, thus asynchronously loading the pages of other content. It is recommended that the scripts do not modify the DOM during loading

Asynchronous scripts must be executed before the Load event of the page and may be executed before or after the Domcontentload event is triggered

Note also only for external files

21.4 usage in XHTML (authors recommend not to read because the front-end developers are using the HTML5 standard)

2.2 Embed code and external files

The best practice in HTML pages is to use external files to contain JavaScript code, with the following advantages

Maintainability puts all JavaScript files in one folder for ease of maintenance and for developers without triggering HTML markup

Focus on editing JavaScript code

The Cache browser caches all external JavaScript files that are linked according to the specific settings, that is, if two pages use the same file at the same time, then

This file only needs to be downloaded once, so the loading speed of the page can be accelerated

Adapting to the future through external folders containing JavaScript without using the previously mentioned XHTML and annotations hack,

2.3 Document Mode

The different primary effects of the initial promiscuous mode (quirks mode) and standard mode mode are implemented via the document type (DOCTYPE) switch
The rendering of CSS content can sometimes affect the execution of JavaScript interpretation

In case of no declaration, the default is promiscuous mode

2.4

Used to display alternative content in browsers that do not support JavaScript, 1. Script 2 is not supported by the browser. browser support, but disabled in the enabled

Script in case the browser does not parse anything in

Moon JavaScript Introduction Chapter 1th and using JavaScript in HTML Chapter 2nd

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.