JavaScript manipulating-bom objects

Source: Internet
Author: User
Tags string format

The browser object model is one of the components of JavaScript, which provides an object that interacts with the browser window independently of the content, and uses the browser object model to interact with the HTML.

First, Window object

1, the Window object is the core of the entire BOM, is the top-level object. All BOM objects are child objects of the Window object

Using a BOM usually enables the following functions:

01. Popup New browser window

02. Move and close the browser window and resize the window

03, in the browser window to achieve the page forward, backward function

2. Common Properties

History information about the URLs that customers have visited

Location information about the current URL

Screen read-only property containing information about client display screens

Syntax: window. Property name = "Property value"

3. Common methods

Prompt () Input dialog box, 01. The first parameter is the prompt statement 02. The second parameter is the default value in the input box, which can be omitted

Alert () Alert dialog box with only one OK button

Confirm () Confirmation dialog box with "OK" and "Cancel" two buttons, click OK return value is True, click cancel button return value is False

Close () Closes the browser window

Open () Opens the browser window, opens the URL for the specified document in a new window

SetTimeout () Delay function after a certain delay, call only once function SetTimeout ("function", number of milliseconds)

SetInterval () Periodic functions call a function setinterval ("function", number of milliseconds) for each period of time

Syntax: Window. Method Name (); Because the Window object is a global object, you can omit the window prefix. Calling alert directly () is equivalent to Window.alert ()

Ii. object of History

Method: 01, Back () load the previous URL in the History object list

02, Forward () load the next URL in the History object list

03. Go () load a specific URL in the History object list go (n) n is a specific number, n>0, the nth page of the forward number. n<0, number of nth pages backward

Third, Location object

1. Properties

Host sets or returns the current host name and port number

Hostname setting or returning the current host name

HREF Sets or returns the full URL

Hash returns all content after # in the URL

Search returns all content after the URL?

2. Methods

Reload () reload the current document

Replace () replaces the current document with a new document

Iv. object of document

1. Properties

Referrer returns the URL syntax loaded into the current document: Document.referrer

The URL syntax for the current document is returned: document. Url

2. Methods

getElementById () returns a reference to the first object that owns the specified ID

Getelementsbyname () returns a collection of objects with the specified name (that is, the Name property)

getElementsByTagName () returns the collection of objects with the specified label name

Write () writes text to the document, an HTML expression, or a JavaScript code

3. Assign a value to the element after getting the element!

InnerHTML: Will compile our text into HTML code
InnerText: Output text as-is

V. JavaScript built-in objects

1. Date Object

Syntax: var date instance =new date (parameter)

01: parameter can be omitted, no parameter returns the current date and time. var nowtime=new Date ()

02: parameter is a string format "MM DD, YYYY, Hh:mm:ss", indicating the date and time. such as Var onetime=new Date ("July 15, 2013, 16:34:28")

Common methods:

getFullYear () returns the year with a value of four digits,

GetMonth () returns the month with a value of 0~11. Note: +1

GetDate () Returns the day of the one month with a value of 1~31

GetHours () returns the number of hours, with a value of 0~23 by 24 binary

Getminutes () returns the number of minutes with a value of 0~59

Getseconds () returns the number of seconds with a value of 0~59

GetDay () Returns the day of the week with a value of 0~6 where 0 represents Sunday

GetTime () returns the number of milliseconds since the moment (January 1, 1970)

2. Math Object

The Math object is a global object of JavaScript and does not need to be created to directly invoke its properties and methods

Common methods:

Ceil (): Rounding up (ceiling function) Math.ceil (25.3) return-Math.ceil (-25.7) return-25

Floor (): Under Rounding Math.ceil (25.7) return Math.ceil (-25.3) return-26

Round (): Rounding Math.ceil (25.7) return to Math.ceil (25.3) return to Math.ceil (-25.7) return -26 Math.ceil (-25.3) return-25

Random (): Returns the number of 0~1 in front of the closed open

VI. periodic functions

1, SetTimeOut ("function name called", number of milliseconds to wait)

Cleartimeout (); clear settimeout () Set timer

Example: Var t1=settimeout ("Alert (' 3 seconds ')", 3000);

Cleartimeout (t1);//Clear Timer

2, SetInterval ("function name called", number of milliseconds for the period interval)

Clearinterval (); clear setinterval () Set timer

Apply similar settimeout () timers

JavaScript manipulating-bom objects

Related Article

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.