Properties and event _javascript Techniques for Window objects in JavaScript

Source: Internet
Author: User
Tags setinterval

Window Object

Window objects represent open windows in the browser.

If the document contains frames (frame or IFRAME tags), the browser creates a Window object for the HTML document and creates an extra window object for each frame.

Note: No open standards apply to window objects, although all browsers support the object.

Windows Object Properties

Property Description
Closed Returns whether the window has been closed.
Defaultstatus Sets or returns the default text in the window status bar.
Document A read-only reference to the Document object. See the Document object.
History A read-only reference to the History object. Please parameter History object.
Innerheight Returns the height of the window's document display area.
Innerwidth Returns the width of the document display area of the window.
Length Sets or returns the number of frames in the window.
Location The Location object for the window or frame. See Location object.
Name Sets or returns the name of the window.
Navigator A read-only reference to the Navigator object. Please parameter Navigator object.
Opener Returns a reference to the window that created this window.
Outerheight Returns the external height of the window.
Outerwidth Returns the external width of the window.
Pagexoffset Sets or returns the X position of the current page relative to the upper-left corner of the window display area.
pageYOffset Sets or returns the Y position of the current page relative to the upper-left corner of the window display area.
Parent Returns the parent window.
Screen A read-only reference to the Screen object. Please parameter screen object.
Self Returns a reference to the current window. is equivalent to the Window property.
Status Sets the text of the window status bar.
Top Return to the topmost window of the ancestors.
Window The Window property is equivalent to the Self property, which contains a reference to the window itself.
  • Screenleft
  • Screentop
  • ScreenX
  • ScreenY
Read-only integer. Declares the x-coordinate and y-coordinate of the upper-left corner of the window on the screen. IE, Safari and Opera support Screenleft and Screentop, while Firefox and Safari support ScreenX and ScreenY.

Windows object Methods

Method Description
Alert () Displays a warning box with a message and a confirmation button.
Blur () Move the keyboard focus away from the top-level window.
Clearinterval () Cancels the timeout set by SetInterval ().
Cleartimeout () Cancels the timeout set by the settimeout () method.
Close () Closes the browser window.
Confirm () Displays a dialog box with a message and a confirmation button and a Cancel button.
Createpopup () Create a pop-up window.
Focus () Give the keyboard focus to a window.
Moveby () You can move the specified pixel relative to the current coordinate of the window.
MoveTo () Moves the upper-left corner of the window to a specified coordinate.
Open () Open a new browser window or look for a named window.
Print () Prints the contents of the current window.
Prompt () Displays a dialog box to prompt the user for input.
Resizeby () Adjusts the size of the window by the specified pixel.
Resizeto () Adjusts the size of the window to the specified width and height.
Scrollby () Scrolls the content according to the specified pixel value.
Scrollto () Scrolls the content to the specified coordinates.
SetInterval () Invokes a function or evaluation expression in the specified period (in milliseconds).
SetTimeout () Calls a function or evaluation expression after a specified number of milliseconds.

The different running environments have different "top-level objects", while in the browser environment, the top-level object is the Window object. Window refers to the current browser window.

Example: var a = 1;

WINDOW.A; 1

The properties of the 1.window object.

(1) Window.name property

Window.name is used to set the name of the browser's current browser window. The feature is that the property remains unchanged after the browser is refreshed.

(2) Window.innerheight property, Window.innerwidth property

These two properties return the height and width of the browser window occupied by the CSS layout of the page. The values for these two properties include the height and width of the browser's scroll bar.

(3) Window.pagexoffset properties and Window.pageyoffset properties.

Window.pagexoffset returns the distance at which the page scrolls horizontally. Window.pageyoffset returns the distance the page scrolls vertically.

(4) IFRAME element

Window.iframe returns an array-like object.

(5) Screen object

Displays information about the device.

Displays the height of the device in pixels
Screen.height
1920
Displays the width of the device in pixels
Screen.width
1080

An event for the 2.window object.

(1) OnError event.

The Oonerror event is an old-fashioned standard way to capture Javascript errors in a Web page.

(2) alert (), Prompt (), confirm ()

Are the methods that browsers use to interact with users. They will pop up a different dialog box.

Example: Alert ("Hello World");

alert (); A pop-up dialog box with only a "OK" button that is often used to inform the user of certain information.

Example: var result = prompt (' Your age? ', 25)

Prompt () Pop-up dialog box, there is an input box, asking the user to enter information, and have "OK" and "Cancel" two buttons. This method is often used to get data entered by the user.

Example: var result = confirm ("How are you doing lately?") ");

Confirm (); The Confirm method returns a Boolean value, returns True if the user clicks "OK", and returns False if the user clicks "Cancel".

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.