Home >Web Front-end >JS Tutorial >What is BOM in JavaScript? Introduction to BOM objects
This chapter brings you what is BOM in JavaScript? Introduction to BOM objects, let everyone understand what BOM means in js and how JavaScript operates BOM objects. It has certain reference value, and there are Friends in need can refer to it, I hope it will be helpful to you.
1. What is BOM
BOM (Browser Object Model) is the browser object model.
BOM provides objects that interact with the browser window independently of content;
Since BOM is mainly used
It is used to manage the communication between windows, so its core object is window;
BOM consists of a series of related objects, and each object
Objects provide many methods and attributes;
BOM lacks standards. The standardization organization for JavaScript syntax is ECMA, and the standardization organization for DOM
Yes W3C, BOM was originally part of the Netscape browser standard.
2. BOM object
1.Window object: current browser form
The window object is the top-level object in js. All variables and functions defined in the global scope will become the properties and methods of the window object, which can be used when calling. to omit window.
Attributes:
status: status bar (currently deprecated by browsers)
opener: who opens mine, if open B is used in A, then B The opener is A
closed: Determine whether the subform is closed
Method:
alert() Pop-up box
confirm() With confirmation, cancel the pop-up box
setInterval() How many seconds to call
clearInterval() Clear setInterval
setTimeout() How many seconds to call
cleartimeout() Clear setTimeout
open() Open a new window
Example :
window.open ("other.html"," _blank","width=200,height=300,top=300");
console: The most commonly used one is console.log() browser console printing
2. Sub-object
The main sub-object Introduction: loation, history, screen.
1), loation jump position
<meta http-equiv="refresh" content="3; url =http://www.hteis.cn";> //不加url指3秒刷新 一次,加url指3秒跳转 window.location.href="popl.html"; location = pop.html location.replace("pop.html") //浏览器不可以后退
2), history history
history.back() == history.go(-1 ) //Return to the previous page
history.go(-2) //The negative number of the parameters in the brackets is to return to the previous steps
Example:
<a href="javascript:history.back()">返回上一页 </a> <a href="javascript:history.go(-2)">第一页</a>
3 ), screen screen
screen.availHeight: the actual height of the screen
screen.availWidth: the actual width of the screen
screen.height: the screen height
screen.width: screen width
Example:
console.log("屏幕实际高度"+screen.availHeight); console.log("屏幕实际宽度"+screen.availWidth); console.log("屏幕高度"+screen.height); console.log("屏幕宽度"+screen.width);
3. The difference between DOM and BOM
1. DOM
The 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 web content, which is HTML and XML API, DOM plans the entire page into a document composed of node levels. DOM for XHTML and HTML. This DOM defines an HTMLDocument and HTMLElement as this The basis for this implementation is that in order to programmatically manipulate the content of this HTML (such as adding certain elements, modifying the content of elements, deleting certain elements), we look at this HTML Make an object tree (DOM tree), itself and all the things in it such as:
These tags are regarded as an object, each object is called a node (node), and the node can be understood as all the objects in the DOM The parent class of Object.
What is DOM used for? It is to operate elements in HTML. For example, if we want to change the title of this web page through JS, just do this:
document.title = ‘how to make love’;
This API makes it possible to change the content of the web page after it is downloaded to the browser.
2. BOM
BOM is the Browser Object Model.
I just said that the DOM is an interface that appears to operate documents, and the BOM, as the name suggests, is actually an interface that appears to control the behavior of the browser.
What can the browser do? For example, to jump to another page, go forward, back, etc., the program may also need to obtain parameters such as the size of the screen.
So BOM is the interface that appears to solve these things. For example, if we want the browser to jump to another page, we only need
location.href =
"http://www.xxxx.com";
This location is an object in the BOM.
4. Summary
In this chapter we learned about some objects that interact with the browser window, such as the window object that can move and resize the browser, and can be used for navigation location Object and history object, the screen object that can obtain browser, operating system and user screen information, you can use document as the entrance to access HTML documents, and manage the frames of the frame Objects etc.
The above is the detailed content of What is BOM in JavaScript? Introduction to BOM objects. For more information, please follow other related articles on the PHP Chinese website!