BOM for javascript
ECMAScript is the core of JavaScript, but if you want to use JavaScript in the Web, then BOM (browser object model) is undoubtedly the real core. BOM provides many objects for accessing browser functions that have nothing to do with any web page content. Over the years, the lack of de facto specifications has made BOM both interesting and problematic, because browser providers will extend it as they wish. Therefore, objects shared between browsers become the de facto standard. These objects exist in the browser, in large part because they provide interoperability with the browser. In order to standardize the most basic parts of JavaScript in the browser, W3C has incorporated the main aspects of BOM into the HTML5 specification.
ps: Excerpted from "Javascript Advanced Programming", BOM is a browser window object and provides many window processing APIs. With more and more webapp frameworks, we need to process different pages and different ajax data in the same window, and we need to be familiar with the content of the BOM.
1. window
The core object of BOM is window, which represents an instance of the browser. In the browser, the window object has a dual role. It is both an interface to access the browser window through JavaScript and a Global object specified by ECMAScript.
Below is the third string property of open
2. Location
location is one of the most useful BOM objects, it provides information about the documents loaded in the current window and also provides some navigation features. In fact, the location object is a very special object because it is both a property of the window object and a property of the document object; in other words, window.location and document.location refer to the same object. The use of a location object is not only reflected in the fact that it stores the information of the current document, but also in the fact that it parses the URL into independent fragments, allowing developers to access these fragments through different properties.
3. History
The history object saves the user's history of surfing the Internet, from the moment the window is opened. Because history is a property of a window object , each browser window, each tab page, and even each framework has its own history object associated with a specific window object. For security reasons, developers cannot know the URLs that users have browsed. However, through the list of pages visited by the user, you can also back and forward without knowing the actual URL.
4. Navigator
The navigator object first introduced by Netscape Navigator 2.0 has now become the de facto standard for identifying client browsers. Although other browsers also provide the same or similar information in other ways (for example, window.clientInfor-mation in IE and indow.opera in Opera), the navigator object is common to all browsers that support JavaScript. As in the case of other BOM objects, the navigator object in each browser also has its own set of properties. The following picture shows more important information about navigator
5. Screen
There are several objects in JavaScript that are not very useful in programming, and screen objects are one of them. The screen object is basically only used to indicate the client's capabilities, including information about the display outside the browser window, such as pixel width and height. The screen object in each browser contains different properties. The following table lists all properties and browsers that support the corresponding properties. Just use the following code to view it
<!DOCTYPE html><html><head><script> console.log(screen);</script></head><body> screen</body></html>