Full introduction to window object attributes in Javascript

Source: Internet
Author: User

Proficient in the use of open, close, alert, confirm, prompt, setTimeout, cleartimeout, setinterval, clearinterval, moveBy, resizeBy, and scrollby methods of window objects
Measure the test taker's knowledge about how to use the moveTo, resizeTo, scrollto, and print methods of window objects.
Familiar with the use of window objects in the status, location, name, self, and opener attributes of window objects is one of the top JavaScript objects on the client, as long as the browser window is opened, whether or not a webpage is opened in the window, an instance of the window object is automatically created when the body, frameset, or frame element is encountered. In addition, the instance of this object can also be created by the window. open () method. Since the window object is the common ancestor of most other objects, You can omit the reference of the window object when calling the methods and properties of the window object. For example, the parameter Doc ument. Write () can be abbreviated to document. Write (). The instance name of the window can be omitted when you release any methods and properties of the window object in the window. For example, when setting the status attribute for the current mywin window, you can only use status instead of mywin. Status. However, the Instance name must be used to call the location attribute, close () method, or open () method in event processing.

6-2-1 window object Method
The window object has the following methods:

 

Open
Close
Alert
Confirm
Prompt
SetTimeout
Cleartimeout
Setinterval
Clearinterval
MoveBy
MoveTo
ResizeBy
ResizeTo
Scrollby
Scrollto
Find
Back
Forward
Home
Stop
Print
Blur
Focus
Captureevent
Enableexternalcapture
Disableexternalcapture
Handleevent
Releaseevent
Routeevent
Scroll

 

1. Open Method
Syntax format:

 

Window. Open (URL, window name, window style)
Function: open a new window and load the webpage with the specified URL address in the window.

 

Note:

 

The open method is used to open a new browser window and add a specified URL address to the new window.

 

;
When opening a new browser window, you can also specify the window name (the second parameter );
When opening a new browser window, you can also specify the window style (the third parameter ),

 

Window style has the following options. You can select multiple options. If you select multiple options, use commas to separate them:
Toolbar: Specifies whether the window has a Standard toolbar. When the value of this option is 1 or yes, it indicates there is a standard

 

Toolbar. If the value of this option is 0 or no, no Standard toolbar exists;
Location: Specifies whether the window has an address toolbar. The options have the same value and meaning as toolbar;
Directories: Specifies whether the window has a linked toolbar. The options have the same value and meaning as the toolbar;
Status: Specifies whether the window has a status bar. The value and meaning of the option are the same as those of toolbar;
Menubar: Specifies whether a window has menus. The options have the same value and meaning as toolbar;
Scrollbar: Specifies whether a scroll bar exists when the document in the current window is greater than the document in the window. The value and meaning of the options are as follows:

 

The same toolbar;
Resizable: Specifies whether the window size can be changed. The value and meaning of the options are the same as those of toolbar;
Width: Specify the window width in pixels, which has been replaced by innerwidth;
Height: Specify the window height in pixels, which has been replaced by innerheight;
Outerwidth: Specify the external width of the window in pixels;
Outerheight: Specify the external height of the window in pixels;
Left: Specify the position of the window to the left of the screen in pixels;
Top: Specify the position of the window from the top of the screen in pixels;
Alwayslowered: specifies that the window is hidden behind all windows. The value and meaning of the option are the same as those of the toolbar.

 

;
Alwaysraised: specifies that the window floats above all windows. The value and meaning of the option are the same as those of the toolbar;
Dependent: Specify the window to be opened as a child window of the current window.

 

Disabled. The value and meaning of the option are the same as those of toolbar;

 

Hotkeys: Set the Security Exit hotkey in a new window without a menu bar. The value and meaning of the options are as follows:

 

The same toolbar;

 

Innerheight: sets the pixel height of the document in the window;

 

Innerwidth: sets the pixel width of the document in the window;

 

Screenx: Set the pixel length between the window and the left boundary of the screen;

 

Screeny: Set the pixel length between the window and the upper boundary of the screen;

 

Titlebar: indicates whether the title bar is visible in a new window. The value and meaning of the option are the same as those of the toolbar;

 

Z-Look: indicates that when the window is activated, it cannot be floated over other windows. The value and meaning of the option are as follows:

 

The same toolbar.

 

The open method returns a reference to the window.

 

Tip: This method is often used to automatically open another window when a webpage is opened.

 

Example 6-2-1: compile a small program, which is used to automatically open another window when the current window is opened.

 

This window does not have a Standard toolbar, address bar, link toolbar, or menu bar, but has a status bar.

 

Open Web address: http://www.dlrtvu.edu.cn.

 

2. Close Method
Syntax format:

 

Window. Close ()
Function: the close method is used to automatically close the browser window.

 

3. Alert Method
Syntax format:

 

Window. Alert (prompt string)
Function: a warning box is displayed. The prompt string text is displayed in the warning box.

 

4. Confirm Method
Syntax format:

 

Window. Confirm (prompt string)
Function: A confirmation box is displayed. A prompt string is displayed in the confirmation box. When you click OK

 

This method returns true, and false if you click "cancel.

 

5. Prompt Method
Syntax format:

 

Window. Prompt (prompt string, default text)
Function: displays an input box. A prompt string is displayed in the input box. The default text is displayed in the input text box.

 

And wait for the user to enter. When the user clicks the "OK" button, the string entered by the user is returned.

 

When you click the cancel button, the return value is null.

 

6. setTimeout Method
Syntax format:

 

Window. setTimeout (Code character expression, in milliseconds)
Function: timed setting. When the specified number of milliseconds is reached, the Code character expression is automatically executed.

 

7. cleartimeout Method
Syntax format:

 

Window. cleartimeout (timer)
Function: cancels the previous scheduled setting. The parameter is the return value when setTimeout is used.

 

8. setinterval Method
Syntax format:

 

Window. setinterval (Code character expression, in milliseconds)
Function: after a time interval is set (the second parameter), the content of "code character expression" is repeatedly executed.

 

9. clearinterval Method
Syntax format:

 

Window. clearinterval (time interval)
Function: cancels the setinterval setting. The parameter is the return value of the setinterval method.

 

10. moveBy Method
Syntax format:

 

Window. moveBy (horizontal displacement, vertical displacement)
Function: Move the specified window according to the specified pixel parameter. The first parameter is the pixel that the window moves horizontally.

 

The two parameters are the pixels that move vertically in the window.

 

11. moveTo Method
Syntax format:

 

Window. moveTo (x, y)
Function: Move the window to the specified coordinate (x, y.

 

12. resizeBy Method
Syntax format:

 

Window. resizeBy (horizontal, vertical)
Function: changes the specified size (x, y) of the current window. If the values of X and Y are greater than 0, they are extended and smaller than 0.

 

To narrow down.

 

13. resizeTo Method
Syntax format:

 

Window. resizeTo (horizontal width, vertical width)
Function: changes the current window to (x, y), and X and Y are respectively width and height.

 

14. scrollby Method
Syntax format:

 

Window. scrollby (horizontal displacement, vertical displacement)
Function: Scroll the content in the window according to the given displacement. If the parameter is a positive number, it will scroll forward. Otherwise, reverse

 

Scroll.

 

15. scrollto Method
Syntax format:

 

Window. scrollto (x, y)
Function: Scroll the content in the window to the specified position.

 

16. Find Method
Syntax format:

 

Window. Find ()
Function: When this method is triggered, a "find" dialog box is displayed, allowing you

 

Find a string on the page of the find method.

 

Note: This attribute is not supported in both ie5.5 and netscape6.0.

 

17. Back Method
Syntax format:

 

Window. Back ()
Function: simulate a user clicking the "back" button on the browser to go to the previous page of the browser.

 

Note: This operation can be performed only when the current page has a previous page.

 

Note: ie5.5 does not support this method. netscape6.0 supports this method.

 

18. Forward Method
Syntax format:

 

Window. Forward ()
Function: simulate a user clicking the "Forward" button on the browser to go to the next page of the browser.

 

Note: This operation can be performed only when the current page has a next page.

 

Note: ie5.5 does not support this method. netscape6.0 supports this method.

 

19. Home Method
Syntax format:

 

Window. Home ()
Function: simulate a user clicking the "home" button on the browser to go to the specified page.

 

Note: ie5.5 does not support this method. netscape6.0 supports this method.

 

20. Stop Method
Syntax format:

 

Window. Stop ()
Function: simulate a user clicking the "stop" button on the browser to terminate the download operation of the browser.

 

Note: ie5.5 does not support this method. netscape6.0 supports this method.

 

21. Print Method
Syntax format:

 

Window. Print ()
Function: simulates the user's clicking the "print" button on the browser to notify the browser to open the Print dialog box and print it.

 

Current page.

22. blur method
Syntax format:

 

Window. Blur ()
Function: removes focus from the window. Be careful when using the focus method, because the focus may be caused.

 

Constantly move in and out.

 

23. focus Method
Syntax format:

 

Window. Focus ()
Function: focus in the window. Be careful when used with The Blur method, because the focus may be less

 

Break forward and remove.

 

24. captureevent Method
Syntax format:

 

Window. captureevent (Event)
Window. captureevent (Event 1 | event 2 |... | event N)
Function: captures all events of a specified parameter. Events that can be captured by the local program itself

 

So programmers can define functions at will to process events. If multiple events need to be captured

 

Separated by the pipe character "|. The event types that can be captured are as follows:

 

Event. Abort

 

Event. blur

 

Event. Change

 

Event. Click

 

Event. dblclick

 

Event. dragdrop

 

Event. Error

 

Event. Focus

 

Event. keydown

 

Event. keypress

 

Event. keyup

 

Event. Load

 

Event. mousedown

 

Event. mousuemove

 

Event. mouseout

 

Event. Mouseover

 

Event. mouseup

 

Event. Move

 

Event. Reset

 

Event. Resize

 

Event. Select

 

Event. Submit

 

Event. Unload

 

25. enableexternalcapture event
Syntax format:

 

Window. enableexternalcapture (Event)
Function: The enableexternalcapture method is used to capture external events passed in through parameters.

 

26. disableexternalcapture event
Syntax format:

 

Window. disableexternalcapture ()
Function: cancels the enableexternalcapture method and terminates the capture of external events.

 

27. handleevent event
Syntax format:

 

Window. handleevent (Event)
Function: The Event processor that triggers the specified event.

 

28. releaseevent event
Syntax format:

 

Window. releaseevent (Event)
Window. releaseevent (Event 1 | event 2 |... | event N)
Function: releases captured events passed in through parameters.

 

The event that can be released is the same as that set by the window. captureevent method.

 

29. routeevent
Syntax format:

 

Window. releaseevent (Event)
Function: transfers all captured events to standard event handling methods for handling, and events that can be transferred.

 

The same as captureevent.

 

30 scroll events
Syntax format:

 

Window. Scroll (x coordinate, Y coordinate)
Function: moves the window to the specified coordinate position.

 

6-2-2 properties of the window object
The window object has the following attributes:

 

Status

 

Statusbar

 

Statusbar. Visible

 

Defaultstatus

 

Location

 

Locationbar

 

Locationbar. Visible

 

Self

 

Name

 

Closed

 

Frames

 

Frames. Length

 

Length

 

Document

 

History

 

Innerheight

 

Innerwidth

 

Menubar

 

Menubar. Visible

 

Opener

 

Outerheight

 

Outerwidth

 

Pagexoffset

 

Pageyoffset

 

Parent

 

Personalbar

 

Personalbar. Visible

 

Scrollbar

 

Scrollbar. Visible

 

Toolbar

 

Toolbar. Visible

 

Top

 

1. Status attributes
Syntax format:

 

Window. Status = string
Function: set or display the current status bar in the browser window.

 

Tip: You can use this property to set the browser window status bar information.

 

2. statusbar attributes
Syntax format:

 

Window. statusbar. Properties
Function: The statusbar attribute is also an object used to access its own visible attribute to ensure

 

Determines whether the status bar is visible.

 

Note: ie5.5 does not support this attribute.

 

3. statusbar. visible attribute
Syntax format:

 

Window. statusbar. Visible
Function: Check whether the status bar is visible. If visible, true is returned. Otherwise, false is returned.

 

Note: ie5.5 does not support this attribute.

 

4. defaultstatus attributes
Syntax format:

 

Window. defaultstatus [= string]
Function: The defaultstatus attribute value is the default display information of the status bar in the browser window.

 

5. Location attribute
Syntax format:

 

Window. Location = URL
Function: Provides the URL Information of the current window or specifies the URL to open the window.

 

6. locationbar attributes
Syntax format:

 

Window. locationbar. Properties
Function: The locationbar attribute can also be viewed as a sub-object, which is used to obtain its own

 

To determine whether the position bar is visible.

 

So far, this property has only one sub-attribute: visible.

 

Note: ie5.5 does not support this attribute.

 

7. locationbar. visible attribute
Syntax format:

 

Window. locationbar. Visible
Function: whether the returned position bar is visible. If visible, true is returned. Otherwise, false is returned.

 

Note: ie5.5 does not support this attribute.

 

8. Self attributes
Syntax format:

 

Window. Self. Method
Window. Self. Properties
Function: This property contains the flag of the current window. With this property, it can be opened in multiple windows.

 

In this case, correctly calling the functions or properties in the current window will not cause confusion.

 

9. Name attributes
Syntax format:

 

Window. Name = Name
Function: return the window name, which is specified when the window. open () method creates a new window.

 

In javascript1.0, this attribute can only be used to read window names.

 

When using javascript1.1, you can use this attribute to create

 

Window to specify a name.

 

10. Closed attributes
Syntax format:

 

Window. Closed
Function: The closed attribute is used to return whether the instance in the specified window is closed. If it is closed, true is returned.

 

Otherwise, flase is returned.

 

11. Frames attributes
Syntax format:

 

Window. Frames ["framework name"]
Window. Frames [value]
Function: The frames attribute is an array used to store each sub-window created by an element in the document (Box

 

Rack) instance. The subscript can be a sequence number or a name specified by the name attribute of the frame element.

 

.

 

12. frames. Length attribute
Syntax format:

 

Window. frames. Length
Function: the frames. Length attribute is used to show the number of subwindow (FRAME) instances in the document.

 

13. Length attribute
Syntax format:

 

Window. Length
Function: returns the number of subwindows in a window.

 

The values of the window. Frame. Length attribute are the same.

 

14. document attributes
Syntax format:

 

Window.doc ument. Event
Window.doc ument. Method
Specified parameter Doc ument. Attribute
Function: the sub-object document of the window object is the core object of JavaScript.

 

Create an instance when the body element is created.

 

15. History attributes
Syntax format:

 

Window. History [value]
Window. History. Method ()
Window. History. Properties
The window object sub-object history is one of the core JavaScript objects. This property contains

 

List of the names and URLs of the accessed pages.

 

16. innerheight attribute
Syntax format:

 

Window. innerheight = Value
Function: return or specify the pixel height of the document in the browser window, which does not include any toolbar or

 

The page height of the window.

 

Note: ie5.5 does not support this attribute.

 

17. innerwidth attribute
Syntax format:

 

Window. innerheight = Value
Function: return or specify the pixel width of the document in the browser window. This width does not include any toolbar or

 

The page decoration width of the window.

 

Note: ie5.5 does not support this attribute.

 

18. menubar attributes
Syntax format:

 

Window. menubar. Attribute
Function: the menubar attribute can also be viewed as a child object. This attribute is used to obtain its own

 

To determine whether the menu bar is visible.

 

So far, this property has only one sub-attribute: visible.

 

Note: ie5.5 does not support this attribute.

 

19. menubar. Visible attributes
Syntax format:

 

Window. menubar. Visible
Function: the menubar. visible attribute is used to return whether the menu bar is visible. If yes, true is returned.

 

Returns false.

 

Note: ie5.5 does not support this attribute.

 

20. Opener attributes
Syntax format:

 

Window. Opener
Window. opener. Method
Window. opener. Attribute
Function: The opener attribute is associated with the parent window that opens the window. When you access the operer attribute in the subwindow

 

The parent window is returned. This attribute allows you to use methods and attributes in the parent window object.

 

21. outerheight attribute
Syntax format:

 

Window. outerheight
Function: The outerheight attribute is used to access the pixel height of a browser window, which includes the toolbar and

 

The height of the decorative edge.

 

Note: ie5.5 does not support this attribute.

 

22. outerwidth attribute
Syntax format:

 

Window. outerwidth
Function: The outerwidth attribute is used to access the pixel width of the browser window, which includes the toolbar and

 

The width of the trim.

 

Note: ie5.5 does not support this attribute.

 

23. pagexoffset attribute
Syntax format:

 

Window. pagexoffset = Value
Function: Specify the current horizontal pixel position in the upper left corner of the document in the browser window. Under Exploitation

 

Before moving moveTo, you can use this attribute to determine whether to move the window. Because this attribute returns

 

You can see the current position of the document relative to the entire page.

 

Note: ie5.5 does not support this attribute.

 

24. pageyoffset attributes
Syntax format:

 

Window. pageyoffset = Value
Function: Specify the current vertical pixel position in the upper left corner of the document in the browser window. Under Exploitation

 

Before moving moveTo, you can use this attribute to determine whether to move the window. Because this attribute returns

 

You can see the current position of the document relative to the entire page.

 

Note: ie5.5 does not support this attribute.

 

25. parent attributes
Syntax format:

 

Window. Parent. Frames [value]
Window. Parent. framesname
Function: access the parent window of each sub-window (Multi-frame.

 

26. personalbar attributes
Syntax format:

 

Window. personalbar. Properties
Function: The personalbar attribute is also an object used to access its own visible attribute.

 

Determines whether the personal column is visible.

 

Note: ie5.5 does not support this attribute.

 

27. personalbar. Visible attributes
Syntax format:

 

Window. personalbar. Visible
Function: determines whether the personal column is visible. If visible, true is returned. Otherwise, false is returned.

 

Note: ie5.5 does not support this attribute.

 

28. scrollbars attributes
Syntax format:

 

Window. scrollbars. Properties
Function: The scrollbars attribute is an object and is used to access its visible attribute.

 

Determines whether the scroll bar is visible.

 

Note: ie5.5 does not support this attribute.

 

29. scrollbars. visible attribute
Syntax format:

 

Window. scrollbars. Visible
Function: scrollbars. Visible is used to determine whether the scroll bar is visible. If visible, true is returned.

 

Returns false.

 

Note: ie5.5 does not support this attribute.

 

30. toolbar attributes
Syntax format:

 

Window. toolbar. Properties
Function: the toolbar attribute is also an object used to access its own visible attribute to determine

 

Whether the toolbar is visible.

 

Note: ie5.5 does not support this attribute.

 

31. toolbar. visible attribute
Syntax format:

 

Window. toolbar. Visible
Function: the toolbar. visible attribute is used to check whether the toolbar is visible. If visible, true is returned,

 

Otherwise, false is returned.

 

Note: ie5.5 does not support this attribute.

 

32. Top attributes
Syntax format:

 

Window. Top. Frames [value]
Window. Top. framename
Window. Top. Method ()
Window. Top. Properties
Function: The top attribute of the window object is used to include the top of all sub-Windows (Multi-frame) loaded into the browser.

 

Layer window information.

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.