8. Javacript Advanced Programming-bom

Source: Internet
Author: User

1. BOM1.1 window

The core object of the BOM is window, which represents an instance of the browser. In the browser, the Window object has a dual identity,

1.1.1 Global scope

Because the window object plays the role of the global object in ECMAScript, all variables and functions declared in the global scope become properties and methods of the Window object.

1.1.2 Window Relationship and framework

If the page contains frames, each frame has its own window object and is saved in the Frames collection. In the Frames collection, the corresponding Window object can be accessed by a numeric index (starting at 0, from left to right, top to bottom), or by the name of the frame.

The top object always points to the highest (most outer) layer of the frame, which is the browser window

The parent object always points to the immediate upper object of the current frame

The self object always points to the Window object

1.1.3 Window Position

There are many properties and methods used to determine and modify the Window object,

Ie,safari,opera and Chrome provide Screenleft and Screentop properties, respectively, to indicate the position of the window relative to the left and top of the screen.

Firefox provides Screenx and screeny with the same window location information

1.1.4 Window Size

It is not easy to determine the window size across browsers, although you cannot determine the size of the browser window itself, but you can get the size of the page viewport

var pagewidth = window.innerwidth;

var pageheight = window.innerheight;

if (typeof pagewidth! = "Number") {

if (Document.compatmode = = "Css1compat") {

PageWidth = Document.documentElement.clientWidth;

PageHeight = Document.documentElement.clientHeight;

}else{

PageWidth = Document.body.clientWidth;

PageHeight =document.body.clientheight;

}

}

1.1.5 Navigating and opening windows

Use window.open () to navigate to a specific URL, or to open a new browser window.

This method accepts four parameters: the URL to be loaded, the window target, a specific string, and whether a new page supersedes the Boolean value of the currently loaded page in the browser history.

1.1.6 intermittent calls and timeout calls

var Timeoutid = setTimeout (function () {

Alert (' Hi ');

}, 1000); Call after one second

Cleartimeout (Timeoutid); Cancel

var intervalid = setinterval (function () {

Alert (' ho ');

},1000); Call 1 times in a second

Clearinterval (intervalid);//Cancel

1.2 Location

Location is one of the most useful BOM objects, which are both properties of the Window object and properties of the Document object.

Property name

Example

Description

Hash

#contents

Returns the hash (#后跟0或多个字符) in the URL and returns an empty string if the URL does not contain a hash

Host

Www.wrox.com:80

Returns the server name and port number (if any)

Hostname

Www.wrox.com

Returns the server name without a port number

Href

Http:/www.wrox.com

Returns the full URL of the currently loaded page. The ToString () method of the Location object also returns this value

Pathname

/wiley/

Returns the directory and/or file name in the URL

Port

8080

Returns the port number specified in the URL. If the port number does not exist in the URL, this property returns an empty string

Protocol

http

Returns the protocol used by the page. Usually http: or https:

Search

? q=javascript

Returns the query string in the URL address. This string starts with a question mark

1.3 Navigator

The fact standard used primarily to identify client browsers

1.4 Screen

A screen object can basically be used to indicate the client's capabilities, including display information outside the browser window.

1.5 History

The history object is a property of the Window object, which holds the user's online historical record. History exists Go,back,forward three methods used to browse through historical records.

Back one page

History.go (-1);

Forward one page

History.go (1);

Forward 2 pages

History.go (2);

Jump to the history of the Baidu.com website

History.go ("baidu.com");

Back one page

History.back ();

Forward one page

History.forward ();

The history object also has a length property, saved in the number of historical records. This number includes all historical records, that is, all forward and backward records.

8. Javacript Advanced Programming-bom

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.