JavaScript Window-Browser object model

Source: Internet
Author: User

The browser object Model (BOM) gives JavaScript the ability to "talk" to the browser.

Browser object Model (BOM)

There is no formal standard for the browser object model (Browser Object Model (BOM)).

Because modern browsers have (almost) implemented the same methods and properties of JavaScript interactivity, they are often considered to be the methods and properties of a BOM.

Window Object

Window objects are supported by all browsers. It represents a browser window.

All JavaScript global objects, functions, and variables automatically become members of the Window object.

A global variable is a property of a Window object.

A global function is a method of a Window object.

Even the document of the HTML DOM is one of the properties of the Window object:

Window.document.getElementById ("header");

The same as this:

document.getElementById ("header");

Window size

There are three ways to determine the size of the browser window (the viewport of the browser, excluding toolbars and scroll bars).

For Internet Explorer, Chrome, Firefox, Opera, and Safari:

    • Window.innerheight-Interior height of the browser window
    • Window.innerwidth-Interior width of the browser window

For Internet Explorer 8, 7, 6, 5:

    • Document.documentElement.clientHeight
    • Document.documentElement.clientWidth

Or

    • Document.body.clientHeight
    • Document.body.clientWidth

Practical JavaScript scenarios (all browsers included):

Example Var w=window.innerwidth
|| Document.documentElement.clientWidth
|| Document.body.clientWidth;

var h=window.innerheight
|| Document.documentElement.clientHeight
|| Document.body.clientHeight;
Try it»

This example shows the height and width of the browser window: (not including toolbars/scrollbars)

Other Window methods

Some other methods:

      • window.open ()-Open a new window
      • Window.close ()-Close the current window
      • Window.moveto ()-Move the current window
      • Window.resizeto ()-Adjusts the size of the current window

JavaScript Window-Browser object model

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.