BOM of javascript, javascriptbom

Source: Internet
Author: User

BOM of javascript, javascriptbom

The BOM (BrowserObjectModel) is also called the browser object model.Describes the methods and interfaces used to interact with the browser. BOM consists of multiple objects, which indicate that the Window object in the browser Window is the top-level object of BOM, and other objects are sub-objects of this object.

JavaScript consists of three parts: ECMAScript, BOM, and DOM. BOM provides many objects for accessing the browser. The following describes three common objects in the browser: window objects, location objects, and history objects.



1. window object


The core object of BOM, which represents an instance of the browser. The window object is at the top of the JavaScript structure. For each opened window, the system automatically defines the window object for it.



1. attributes and methods of Objects
Window objects have a series of attributes, which are also objects.



You can call properties and methods in window. properties, window. Method (), or direct properties and methods. For example, window. alert () and alert () mean one thing.


2. System dialog box
The browser can call the alert (), confirm (), and prompt () Methods to display information to users in the system dialog box. The system dialog box is irrelevant to the webpage displayed in the browser and does not contain HTML.

(1) A warning is displayed.

Alert ('lil'); // a warning is displayed directly.

(2) Confirmation and Cancellation

Confirm ('Confirm or cancel'); // if (confirm ('Confirm or cancel ')) {// confirm itself has the returned value alert ('You have pressed OK! '); // Press OK to return true} else {alert (' You have clicked cancel! '); // Press Cancel to return false}
(3) enter a prompt box

Var num = prompt ('enter a number', 0); // two parameters, one prompt, one value alert (num); // return value can be obtained


3. New window

You can use the window. open () method to navigate to a specific URL or open a new browser window. It can accept four parameters:

1. URL to be loaded;
2. Window name or window target;
3. A feature string;
4. indicates whether the new page replaces the Boolean value of the currently loaded page in the browser record

Open ('HTTP: // www.baidu.com '); // create a page and open baidu open ('HTTP: // www.baidu.com', 'baidu '); // create a page, name the window, and open Baidu open ('HTTP: // www.baidu.com ',' _ parent '); // open Baidu in the window on this page, _ blank is new

Ii. location object


Location is one of the BOM objects. It provides information related to the documents loaded in the current window and some navigation functions. In fact, the location object is the property of the window object and also the property of the document Object. Therefore, the window. location and document. location are equivalent.

<Strong> <span style = "font-size: 18px;"> alert (location); // obtain the current URL </span> </strong>



3. history Object


The history object is the property of the window object. It stores the user's online records, starting from the moment the window is opened.



(1) Jump to the previous URL

Function back () {// jump to the previous URLhistory. back ();}

(2) jump to the next

Function forward () {// jump to the next URLhistory. forward ();}

(3) Jump to the URL of the specified history

Function go (num) {// jump to the URLhistory. go (num);} of the specified history );}
PS: You can determine whether there are historical records by judging history. length = 0.


Summary:

The ability of the JavaScript BOM to pop up a new browser window; the ability to move, close, and change the size of the browser window; the ability to provide navigation objects for detailed WEB browser information; provides a browser to load local objects with detailed page information. In short, BOM provides an object structure that can interact with browser windows, increasing user experience.


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.