Practical JS Series--bom common Objects

Source: Internet
Author: User

Background:

Recently, when embarking on the project, I realized the lack of JS. Although I've seen a lot of javascript videos, it's not always a big, hard case in a real project. So the basics of JavaScript need to be solid, and there's a series of blogs. This series of more emphasis on practical, theoretical parts can be see before the blog.


The BOM (Browser object mode) browser objects model is an important part of JavaScript. It provides a series of objects that are used to interact with browser windows, which are commonly referred to as BOMs.



As can be seen from the diagram, the Window object is the parent object of all objects in the BOM.


1. Window Object--bom Core

Window object, as the name implies.

It represents the entire browser window and is used primarily to manipulate the browser window.

The operation of the window is mainly the adjustment of coordinates, the screen coordinates as shown:


The common methods are:

1) Relative operation

moveby--Mobile

resizeby--resizing

2) Absolute operation

MoveTo

Resizeto


2. Document Object

It is a property of the Window object that can be used to work with the page document, but many features are deprecated.

Examples of common methods:

<script type= "Text/javascript" >        function Test () {            //Navigate to New page            document. URL = "http://www.baidu.com"            //output content            document.write (document. URL);  Window.document.write (document. URL) function same        }    </script>



3. Location Object

It is a property of the Window object and the Document object that is used to parse and set the URL address of the page.

Examples of common methods:

           URL attribute similar to document            location.href= "http://baidu.com";            Reload page            location.reload (TRUE);


4. Navigator Object

is considered to be the most important object, it contains a series of browser information properties.

UserAgent is the most commonly used property to complete the browser's judgment.

            var auseragent = navigator.useragent;             document.write (auseragent);

Show Results:


5. Screen Object

is also one of the properties of the Window object and is used primarily to obtain the user's screen information.

Examples of common methods:

document.write ("screen height is:" + screen.availheight+ "" + "screen width is:" +screen.availwidth);

Show Results:



Summarize:

JavaScript is the foundation. JavaScript is not good, but directly to use the functions provided in jquery, there is a sense of knowledge overhead. Know it, do not know why. JS can also help you understand the Ajax, so, JS learned to use, to be able to use, rather than write a simple registration event to Baidu, so inefficient, too unprofessional.


Practical JS Series--bom common Objects

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.