(7) Javascript-bom

Source: Internet
Author: User

Window Object

Global Scope

In the browser, the Window object has a dual role, which is both an interface for accessing the browser window through JavaScript, and the Global object specified by the ECMAScript.

All variables and functions declared in the global scope become properties and methods of the Window object

var age =; function Sayage () {alert (this///////29 

window relationships and frameworks

。。

Window position

Use the following code to get the position of the left and top of the window across the browser

var leftpos = (typeof Window.screenleft = = "Number")? Window.screenLeft:window.screenX; var toppos = (typeof Window.screentop = = "Number")? Window.screenTop:window.screenY;

MoveTo () receives the x and Y coordinate values of the new position , while Moveby () receives the number of pixels moving in both horizontal and vertical directions

// Move the window to the upper-left corner of the screen Window.moveto (0,0); // move the window down 100 pixels window.moveby (0,100); // Move the window to (200,300)Window.moveto (200,300); // Move the window to the left 50 pixels Window.moveby ( -50,0)

It is important to note that these two methods may be disabled by the browser, and neither of these methods is applicable to the framework, only the outermost window object can be used

Window Size

Outerwidth and Outerheight return the dimensions of the browser window itself
Innerwidth and Innerheight indicate the size of the Page view area in the container (minus the border width)

The size of the browser window can be adjusted using the Resizeto () and Resizeby () methods

where Resizeto () receives the new width and new height of the browser window, while Resizeby () receives the difference between the width and height of the new window and the original window

// adjusted to 100x100Window.resizeto (+); // adjusted to 200x150Window.resizeby (+); // adjusted to 300x300Window.resizeto (300, 300);

These two methods may be disabled by the browser, and neither of these methods is applicable to the framework, only the outermost window Object can be used

Navigating and opening Windows

The window.open () method can navigate to a specific URL, or you can open a new browser window to receive 4 parameters:
1. URL to load
2. Window target
3. An attribute string
4. A Boolean value that indicates whether the new page supersedes the currently loaded page in the browser history

Usually only the first argument is passed, and the last parameter is only used without opening a new window

(7) Javascript-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.