About Dom & BOM

Source: Internet
Author: User

JavaScript consists of three parts: ecmascript, Dom, and Bom. Depending on the host (browser), the specific expressions are also different. IE and other browsers have different styles.

1. Dom is W3C standard; [common standards for all browsers]
2. Bom is used by various browser vendors according to Dom
Implementation on the respective browsers; [different definitions are displayed in different browsers, with different implementation methods]
3. Window is a BOM object, not a JS object;

Dom (Document Object Model) is an application interface (API) for HTML and XML ).

Bom mainly processes browser windows and frameworks. However, browser-specific JavaScript extensions are usually considered part of BOM. These extensions include:

A new browser window is displayed.

Move and close the browser window and resize the window

Locating objects with detailed web browser Information

Screen Object that provides detailed information about the user's screen resolution

Cookie support

IE extends BOM and adds the activexobject class. ActiveX objects can be instantiated through JavaScript.

Javacsript accesses, controls, and modifies the client (browser) by accessing the browser object model object. Because the BOM window contains the document, the properties and methods of the window object can be directly used and perceived. Therefore, you can directly use the document attribute of the window object, the document attribute allows you to access, retrieve, and modify the content and structure of XHTML documents. Because the document object is the root node of the DOM (Document Object Model) model. It can be said that BOM contains dom (object). The browser provides the BOM object for access, and then accesses the DOM object from the BOM object, thus, JS can operate the documents read by browsers and browsers. Where
Dom includes: Window

Window objects include attributes: Document, location, Navigator, screen, history, and frames.

The document root node contains subnodes: forms, location, anchors, images, and links.

The most fundamental object of Dom is the sub-object of the window object of BOM.

Differences: Dom describes the methods and interfaces for processing web content. Bom describes the methods and interfaces for interacting with browsers.

 1.1 Differences Between Dom, document, BOM, and window

DomThe full name is Document Object Model, which is the Document Object Model. Is a tree-based API for XML. Describes the methods and interfaces for processing webpage content. It is an HTML and xml api. Dom plans the entire page as a document composed of node levels. Dom for XHTML and HTML. This Dom defines an htmldocument and htmlelement as the basis for this implementation, that isTo operate the HTML content programmatically(For example, adding some elements, modifying the content of elements, and deleting some elements), we regard this HTML as an object tree (DOM tree ), it and everything in it, such as <div> </div>, are regarded as an object, and each object is called a node ), nodes can be understood as the parent class of all objects in the Dom.

 

 

What is the use of Dom? This is to manipulate the elements in HTML. For example, we need to change the webpage title through JS, just like this:

Document. Title = 'how to make love ';

This API makes it possible to change the content of the webpage after the webpage is downloaded to the browser.

Document

When a browser downloads a webpage, which is usually HTML, it is called document (of course, this is also a node in the DOM tree, document is usually the root node of the entire DOM tree. This document contains attributes such as the title (document. Title) and URL (document. url), which can be accessed directly in Js.

You can have multiple documents in a browser window. For example, each page loaded by IFRAME is a document.

In JS, you can access its subnodes through document (in fact, any node can), such

Document. Body; document. getelementbyid ('xxx ');


BOM

Bom is the browser object model, which is the browser object model.


As mentioned earlier, Dom is used to operate the interface that appears in the document. The BOM is actuallyTo control browser behaviorThe interface that appears.

What can a browser do? For example, to jump to another page, forward, back, and so on, the program may also need to obtain parameters such as the screen size.

Therefore, Bom is the interface to solve these problems. For example, to redirect a browser to another page, you only need

Location. href = "http://www.xxxx.com ";


This location is an object in Bom.

Window

Window is also an object of BOM. Apart from the "full-disclosure object" in programming sense, this object can be used to obtain the window position, determine the window size, and pop-up dialog boxes. For example, to close the current window:

Window. Close ();

Dom is an API used to operate a document. Document is an object of this document;
Bom is used to operate the APIs that appear in the browser, and window is an object of it.

About Dom & BOM

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.