Windows window objects in JavaScript basics

Source: Internet
Author: User
Window object in JavaScript
He is the largest object in JavaScript, and it describes a browser window. In general, to reference its properties and methods, do not need to use the "window.xxx" this form, and directly using "XXX". A frames page is also a window.

Window objects have the following properties:



The name window, determined by the connection on which it is opened (<a target= >) or frames page (<frame name= "..." >) or the Open () method called by a window (see below). Generally we do not use this attribute.

Status refers to what is displayed in the status bar below the window. You can change the display of the status bar by assigning values to status.

Opener usage: window.opener; Returns the Window object that opens this window. Note: A Window object is returned. If the window is not open by another window, this property returns Null in Netscape and "undefined" (undefined) in IE. Undefined to a certain extent equals null. Note: Undefined is not a JavaScript constant, and if you attempt to use "undefined", it really returns "undefined."

Self refers to the window itself, which returns objects that are exactly the same as window objects. The most commonly used is "self.close ()", placed in the <a> tag: "<a href=" Javascript:self.close () "> Close window </a>".

Parent returns the Frame Page object to which the window belongs.

Top returns the topmost Frame Page object that occupies the entire browser window.

History historical objects, see below.

Location Address object, see below.

Document documents object, see below.



Window objects have the following methods:
The first method is open () opens a window.
Usage:
Open (<url String, < window name string, < parameter string >);

Description



<url string: Describes which web page the open window opens. If you leave Blank ('), you do not open any Web pages.

< window name string: Describes the name of the window being opened (window.name), you can use the ' _top ', ' _blank ', and other built-in names. The name here is the same as "<a href=" ... "target=" ... "target" property is the same in >.

< parameter string: Describes the appearance of the window being opened. If you only need to open a normal window, the string is left blank ('), and if you want to specify the appearance, write one or more arguments in the string, separated by commas.


For example: Open a clean window of x 100:
Open (', ' _blank ', ' width=400,height=100,menubar=no,toolbar=no,
Location=no,directories=no,status=no, Scrollbars=yes,resizable=yes ')

The parameters of the Open ()



The number of pixels off the top of the screen at the top of the top=# window

left=# window left the number of pixels leaving the left side of the screen

Width of the width=# window

Height of the height=# window

Menubar= ... Window has no menu, value Yes or no

Toolbar= ... Window has toolbar, value Yes or no

Location= ... window has no address bar, value yes or no

Directories= ... window has no connection area, value Yes or no

Scrollbars= ... Window has scroll bar, value Yes or no

Status= ... Window has status bar, value Yes or no

Resizable= ... window is not resized, value yes or no


Note: The open () method has a return value that returns the Window object it opens. Like what
var newwindow = open (', ' _blank ');

This assigns a new window to the "NewWindow" variable, which can then be controlled by the "NewWindow" variable.

Close () Closes a window that is already open.
Usage:
Window.close ()

Or
Self.close ()

The main function is to close the window;
< Window object >.close (): Closes the specified window. Note If the window has a status bar, the browser warns: "The Web page is trying to close the window. "Then waits for the user to select whether or not if there is no status bar, calling the method closes the window directly.
Another window object has the following methods



Blur () Moves the focus away from the window, and the window changes to an inactive window.

Focus () is the window that gets the spotlight and becomes the active window. However, in Windows 98, this method only blinks the title bar of the window and the corresponding button on the taskbar, prompting the user that the window is trying to gain focus.

Scrollto () Usage:[< window object. Scrollto (x, y); Scrolls the window so that the document (x, y) points from the top left corner to the upper-left corner of the window.

Scrollby () Usage:[< window object. Scrollby (DeltaX, DeltaY), scrolling the window to the right deltax pixels, scrolling down deltay pixels. If a negative value is taken, it scrolls in the opposite direction.

Resizeto () Usage:[< window object. Resizeto (width, height); Make window resize to wide width pixel, high height pixel.

Resizeby () Usage:[< window object. Resizeby (Deltawidth, deltaheight), resizing the window, increasing the deltawidth pixel width, and increasing the deltaheight pixel height. If a negative value is taken, it is reduced.

Alert () Usage: alert (< string >); pops up a dialog box that contains only the OK button, which displays < string >, and the entire document reads and the Script runs until the user presses OK.

Confirm () Usage: Confirm (< string >), pop Up a dialog box with OK and Cancel buttons, display < string > content, ask the user to make a choice, the entire document read, Script run will be paused. Returns a true value if the user presses OK, and returns a value of False if "cancel" is pressed.

Prompt () Usage: prompt (< string >[, < initial value), pop up a dialog box with confirmation "Cancel" and a text box, display < string > content, ask the user to enter some data in the text box, read the entire document, The Script's run will be paused. If the user presses confirm, returns what is already in the text box and returns a null value if the user presses Cancel. If you specify < initial value, the text box will have a default value.



The Window object has the following events:
Window.onload occurs when all the documents have been downloaded. All download means not only the HTML file, but also contains pictures, Plug-ins, controls, small programs and all the contents are downloaded. This event is a window event, but when you specify an event handler in HTML, we write it in the <body> tag.
Window.onunload occurs when a user exits a document (or closes a window, or goes to another page). Like the onload, write in the HTML and write to the <body> tag.



Window.onresize occurs when the window is resized.

Window.onblur occurs when the window loses focus.

Window.onfocus occurs when the window gets the focus.

Window.onerror occurs when an error occurs. Its event handlers are often called "Error Handlers" (Handler) to handle errors. The above has been introduced, to ignore all errors, the use of:
function Ignoreerror () {
return true;
}
Window.onerror = Ignoreerror;
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.