Window objects in JavaScript

Source: Internet
Author: User
The Window object in JavaScript is the largest object in JavaScript, which describes a browser Window. Generally, to reference its attributes and methods, you do not need to use the "window. xxx" format, but directly use "xxx ". A framework page is also a window. Window objects have the following attributes: & nbspSyntax

Window objects in JavaScript
It is the largest object in JavaScript and describes a browser window. Generally, to reference its attributes and methods, you do not need to use the "window. xxx" format, but directly use "xxx ". A framework page is also a window.

Window objects have the following attributes:
 

Name window name, opened by its connection () or frame page () Or the open () method called by a window (see below. This attribute is generally not used.
 
Status indicates the content displayed in the "status bar" under the window. By assigning values to status, you can change the display of the status bar.
 
Opener usage: window. opener; return the window object that opens the window. Note: A window object is returned. If the window is not opened by another window, null is returned for this attribute in Netscape; "undefined" is returned for IE ). Undefined is equal to null to some extent. Note: undefined is not a JavaScript constant. If you attempt to use "undefined", "undefined" is returned.
 
Self refers to the window itself, which returns the same object as the window object. The most common is "self. close ()", which is placed in the tag: "close the window ".
 
Parent returns the frame Page Object of the window.
 
Top returns the framework page Objects occupying the top of the entire browser window.
 
History object, see.
 
Location address object, see.
 
Document Object, see.
 


The Window object has the following methods:
The first method is open () to open a window.
Usage:
Open ( , <窗口名称字符串> , <参数字符串> );
Note:
 

: Describe which web page is opened in the window. If () is left blank, no webpage is opened.
 
<窗口名称字符串> : The name of the window to be opened (window. name). You can use built-in names such as _ top and _ blank. The name here is the same as the "target" attribute in.
 
<参数字符串> : Describes the appearance of the Opened Window. If you only need to open a normal window, leave the string blank (). If you want to specify the appearance, write one or more parameters in the string, separated by commas.
 

For example, open a clean window of 400x100:
Open (, _ blank, width = 400, height = 100, menubar = no, toolbar = no,
Location = no, directories = no, status = no, scrollbars = yes, resizable = yes)
Open () Parameters
 

Top = # number of records that exit from the top of the screen at the top of the window
 
Left = # number of records left when the left side of the window leaves the screen
 
Width = # window width
 
Height = # window height
 
Menubar =... Is there any menu in the window? The value is yes or no.
 
Toolbar =... does the window have a toolbar? The value is yes or no.
 
Location =... Is there an address bar in the window? The value is yes or no.
 
Directories =... whether there is a connection area in the window. The value is yes or no.
 
Scrollbars =... does the window have a scroll bar? The value is yes or no.
 
Status =... does the window have a status bar? values: yes or no
 
Resizable =... the window is not adjusted. The value is yes or no.
 

Note: The open () method has a return value, which is the window object it opens. For example
Var newWindow = open (, _ blank );
In this way, a new window is assigned to the "newWindow" variable, and the window can be controlled through the "newWindow" variable.

Close () closes an opened window.
Usage:
Window. close ()
Or
Self. close ()
The main function is to close this window;
<窗口对象> . Close (): close the specified window. Note: If the window has a status bar, the browser will warn after calling this method: "The webpage is trying to close the window. Are you sure you want to close it ?" Then wait for the user to choose whether or not. If there is no status bar, calling this method will close the window.
In addition, the Window object also has the following method:
 

Blur () removes the focus from the window and changes the window to an "inactive window ".
 
Focus () is the focus of the window and changes to "activity window ". However, in Windows 98, this method can only Flash the title bar of the window and the corresponding buttons on the taskbar, prompting the user that the window is trying to get the focus.
 
ScrollTo () usage :[ <窗口对象> .] ScrollTo (x, y); scroll the window to make the document scroll from the (x, y) points in the upper left corner to the upper left corner of the window.
 
ScrollBy () usage :[ <窗口对象> .] ScrollBy (deltaX, deltaY); scroll the deltaX pixel to the right of the window, and scroll down the deltaY pixel. If a negative value is obtained, it is rolled in the opposite direction.
 
ResizeTo () usage :[ <窗口对象> .] ResizeTo (width, height); enables the window to be adjusted to the width, width, and height pixels.
 
ResizeBy () usage :[ <窗口对象> .] ResizeBy (deltaWidth, deltaHeight); adjust the window size, increase the width of deltaWidth pixels, and increase the height of deltaHeight pixels. If the value is negative, the value is reduced.
 
Alert () usage: alert ( <字符串> ); A dialog box containing only the "OK" button is displayed. <字符串> The reading of the entire document and running the Script will be paused until the user presses "OK ".
 
Confirm () usage: confirm ( <字符串> ). A dialog box containing the "OK" and "cancel" buttons is displayed. <字符串> The user is required to make a selection. Reading the entire document and running the Script will be suspended. If you press "OK", true is returned. If you press "cancel", false is returned.
 
Prompt () usage: prompt ( <字符串> [, <初始值> ]); A dialog box containing "OK", "cancel", and a text box is displayed. <字符串> The user is required to input some data in the text box. Reading the entire document and running the Script will be suspended. If the user presses "OK", the existing content in the text box is returned. If the user presses "cancel", the return value is null. If you specify <初始值> , The default value is displayed in the text box.
 


Window objects have the following events:
The window. HTML file contains all the images, plug-ins, controls, applets, and other content downloaded. This event is a window event, but when you specify an event handler in HTML, we write it inMarked.
Window. onunload; occurs when the user exits the document (or closes the window, or goes to another page. Like onload, it should be written in HTMLMark.
 

Window. onresize; occurs when the window is adjusted.
 
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 Handler is usually called an Error Handler to handle errors. As described above, to ignore all errors, use:
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.