Home > front end >  Browser JavaScript object model of BOM
Browser JavaScript object model of BOM

Time:09-20

BOM
- BOM: browser object model//host object
- BOM provides many object, used to access the browser's function, these functions have nothing to do with any web content,
- BOM of the individual parts of the browser into one object, by modifying the properties of these objects, we call them the
Method, to control the actions of the browser

In simple terms: BOM enables us to operation by JS browser, provides a set of objects in the BOM, used to complete the work with the browser,
BOM object:
Window object
1.- represent the entire browser window, the window at the same time global object is also a web page
2. The Navigator object (netscape)
- represent the current browser information, through the object can be used to identify different browser
3. The Location of the
- represent the current information, the web browser address bar through the Location can access to the address bar information, or operating browser page jump
4. The History
- on behalf of the browser's history, can pass the object to manipulate the browser's history, because of privacy issues, the objects are not
Can get detailed historical records, only the browser page forward or backward, operation and the operation is only valid when visit
5. Screen
- on behalf of the user's screen information, through the object can obtain relevant information to the user's display

Are all these BOM object in the browser as a window object of property preservation, can through the window object to use, also can direct
By using the

The Navigator
- represent the current browser information, through object can be used to identify different browser
- for historical reasons, some attributes of the Navigator object is can't help us to identify the browser
- usually we can only use the userAgent to judge the browser's information, the userAgent is a string, the string
Contains a browser used to describe the information content, different browsers have not through the userAgent
In Firefox userAgent
Mozilla/5.0 (Windows NT 10.0; Win64. X64; The rv: 72.0) Gecko/20100101 Firefox/72.0
The Chrome userAgent
Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/81.0.4000.3 Safari/537.36
In IE8 userAgent
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 10.0; WOW64. Trident/7.0; . NET4.0 C;
. NET4.0 E; The.net CLR 2.0.50727; The.net CLR 3.0.30729; The.net CLR 3.5.30729; InfoPath. 3)
Internet explorer 9 the userAgent
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 10.0; WOW64. Trident/7.0; . NET4.0 C;
. NET4.0 E; The.net CLR 2.0.50727; The.net CLR 3.0.30729; The.net CLR 3.5.30729; InfoPath. 3)
Build the userAgent
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 10.0; WOW64. Trident/7.0; . NET4.0 C;
. NET4.0 E; The.net CLR 2.0.50727; The.net CLR 3.0.30729; The.net CLR 3.5.30729; InfoPath. 3)
The userAgent IE11
Mozilla/5.0 (Windows NT 10.0; WOW64. Trident/7.0; . NET4.0 C; . NET4.0 E; The.net CLR
2.0.50727; The.net CLR 3.0.30729; The.net CLR 3.5.30729; InfoPath. 3; The rv: 11.0) like Gecko
Example: on the basis of judging userAgent browser
The console. The log (the navigator. UserAgent);
Var ua=window. The navigator. UserAgent;
If (/Firefox/i.t est (ua)) {
Alert (" firefox ");
} else if (/Chrome/i.t est (ua)) {
Alert (" Google browser ");
} else if (msie/i.t est (ua)) {//no msie IE11
Alert (" IE browser ");
} else if (" ActiveXObject "in Windows) {//that can identify IE11
Alert (" IE browser ");
}
If through the navigator userAgent cannot judge, can also with some peculiar to the browser object, to judge the clear
Browser information, such as: ActiveXObject (IE contains)

The History
- object can be used to operate the browser after forward or backward page
- length returns the number of the URL in browser history list,

The method of the History object:
Back () to load a URL before in the history list,
Forward () to load a URL in the history list,
The go () to load a particular page in the history list,
Example: the go (1)==& gt; The back ()
The go (1)==& gt; Forward ()
The Location
- the object encapsulates the browser's address bar information
/*
The Location object attribute
Property description
Hash sets or returns from the well number (#) to the URL (anchor),
The host Settings or returns the current URL hostname and a port number,
The hostname sets or returns the current URL hostname,
Href sets or returns the complete URL,
The pathname sets or returns the current URL path,
Port port sets or returns the current URL,
The agreement protocol sets or returns the current URL,
The search Settings or return from a question mark (?) Start URL (query),
*/

If print directly the location, you can obtain information on the address bar (the completion of the current page path)
Example: the console log (lacation);
If directly amend the location attribute to a full path or a relative path, the page will automatically jump to the path, we
And generates relative history
Example: the location="https://www.baidu.com/";
//direct assignment, is to modify the path (equivalent to the original path covered)
The assign ()
- used to jump to other pages, and directly modify the location as
Example: the location of the assign (" https://www.baidu.com/");
Reload ()
Function and refresh button to reload the current document, as well as
- if you pass a true as a parameter in the method, will be forced to empty the cache refresh the page
Example: the location. Reload (true);
The replace ()
- with a new document to replace the current document, call end will jump page
- not generate history records, cannot use the back button back
Example: the location. The replace (" https://www.baidu.com/");
  • Related