What's the difference between the Browser Object Model and the Document Object Model?

前端 未结 5 1892
旧巷少年郎
旧巷少年郎 2020-12-08 20:14

What is the difference between the two?

5条回答
  •  甜味超标
    2020-12-08 20:58

    BOM

    This is an informal term as there is no W3C or WHATWG standard that mentions it.

    One simple definition would be that the BOM encompasses the entire object structure which is accessible via scripting in the browser, beginning with the window object which "contains everything else", since it's the global object.

    The window object contains lots of properties (try console.dir( window );). These properties are specified in numerous web-standards. The "core" specification of the window object is as of now still specified in the HTML standard - see here, but I guess it's only a matter of time until the editors decide to transfer this specification into a separate standard. I'm definitively rooting for a "BOM" or "Browser Environment" standard to make things more logical and appropriate.

    DOM

    This on the other hand is a formal term. You can find definitions of this term in various standards, for instance the DOM4 standard states:

    The DOM is a language- and platform neutral interface that allows programs and scripts to dynamically access and update the content and structure of documents.

    Notice how the emphasis is on documents. Unlike the BOM which is basically and umbrella term for all the APIs in the browsers, DOM are only those APIs which deal with documents.

    A simple definition would be that the DOM is implemented as the document object (which is the root of the DOM tree btw). Basically, the DOM tree (and everything inside it) can be considered part of the DOM. Analogously, everything beyond the DOM-tree is not part of the DOM.

    beyond the DOM-tree == all the properties of window except the document object

提交回复
热议问题