Window object
The window object is supported by all browsers. It represents the browser window.
All JavaScript global objects, functions, and variables automatically become members of the window object.
Global variables are properties of the window object.
Global functions are methods of the window object.
1. open method
Grammar format:
window.open(URL, window name, window style)
Function: Open a new window and load the web page with the specified URL address in the window.
Description:
The open method is used to open a new browser window and load a specified URL address in the new window;
When the open method opens a new browser window, you can also specify the name of the window (the second parameter);
When the open method opens a new browser window, you can also specify the style of the window (the third parameter),
The window style has the following options. These options can be selected multiple times. If multiple selections are made, separate the options with commas:
toolbar: Specifies whether the window has a standard toolbar. When the value of this option is 1 or yes, it means there is a standard toolbar; when the value of this option is 0 or no, it means there is no standard toolbar;
location: Specifies whether the window has an address toolbar. The value and meaning of the option are the same as toolbar;
directories: Specifies whether the window has a link toolbar. The value and meaning of the option are the same as toolbar;
status: Specifies whether the window has a status bar. The value and meaning of the option are the same as toolbar;
menubar: Specifies whether the window has a menu. The value and meaning of the option are the same as toolbar;
scrollbar: Specifies whether there is a scroll bar when the current window document is larger than the window. The value and meaning of the option are the same as toolbar;
resizable: Specifies whether the window can be resized. The value and meaning of the option are the same as toolbar;
width: Specifies the width of the window in pixels, replaced by innerWidth;
height: Specifies the height of the window in pixels, replaced by innerHeight;
outerWidth: Specifies the outer width of the window in pixels;
outerHeight: Specifies the outer height of the window in pixels;
left: Specifies the position of the window from the left side of the screen in pixels;
top: Specifies the position of the window from the top of the screen in pixels;
alwaysLowered: The specified window is hidden behind all windows. The value and meaning of the option are the same as toolbar;
alwaysRaised: The specified window floats on top of all windows. The value and meaning of the option are the same as toolbar;
dependent: Specifies that the opened window is a child window of the current window and will be closed when the parent window is closed. The value and meaning of the option are the same as toolbar;
hotkeys: Set the hotkey for safe exit in a new window without a menu bar. The value and meaning of the option are the same as toolbar;
innerHeight: Set the pixel height of the document in the window;
innerWidth: Set the pixel width of the document in the window;
screenX: Set the pixel length of the window from the left edge of the screen;
screenY: Set the pixel length of the window from the upper border of the screen;
titleBar: Indicates whether the title bar is visible in the new window. The value and meaning of the option are the same as toolbar;
z-look: Indicates that when the window is activated, it cannot float on top of other windows. The value and meaning of the option are the same as toolbar.
The open method returns a reference to the window.
Tip: This method is often used to automatically open another window when opening a web page.
2. close method
Grammar format:
window.close()
Function: The close method is used to automatically close the browser window.
3. alert method
Grammar format:
window.alert(prompt string)
Function: Pop up a warning box and display the prompt string text in the warning box.
4. confirm method
Grammar format:
window.confirm(prompt string)
Function: Display a confirmation box, display the prompt string in the confirmation box, when the user clicks the "OK" button
This method returns true when "Cancel" is clicked and false when "Cancel" is clicked.
5. prompt method
Grammar format:
window.prompt(prompt string, default text)
Function: Display an input box, display the prompt string in the input box, and display the default text
in the input text box
This, and waits for user input, when the user clicks the "OK" button, returns the string entered by the user, when
When the Cancel button is clicked, a null value is returned.
6. setTimeout method
Grammar format:
window.setTimeout(code character expression, milliseconds)
Function: Timing setting, when the specified number of milliseconds is reached, the code character expression is automatically executed.
7. clearTimeout method
Grammar format:
window.clearTimeout(timer)
Function: Cancel the previous timing setting. The parameter is the return value when set with setTimeout.
8. setInterval method
Grammar format:
window.setInterval(code character expression, milliseconds)
Function: After setting a time interval (second parameter), repeatedly execute the content of "code character expression"
9. clearInterval method
Grammar format:
window.clearInterval(time interval)
Function: Cancel the timing set by setInterval. The parameter is the return value of the setInterval method.
10. moveBy method
Grammar format:
window.moveBy(horizontal displacement, vertical displacement)
Function: Move the specified window according to the given pixel parameters. The first parameter is the pixel by which the window moves horizontally, the first parameter is
The two parameters are the pixels by which the window is moved vertically.
11.moveTo method
Grammar format:
window.moveTo(x,y)
Function: Move the window to the specified specified coordinates (x, y).
12. resizeBy method
Grammar format:
window.resizeBy(horizontal,vertical)
Function: Change the current window to the specified size (x, y). When the values of x and y are greater than 0, it is expanded, and when it is less than 0
to reduce.
13. resizeTo method
Grammar format:
window.resizeTo(horizontal width, vertical width)
Function: Change the current window to (x, y) size, where x and y are the width and height respectively.
14. scrollBy method
Grammar format:
window.scrollBy(horizontal displacement, vertical displacement)
Function: Scroll the content in the window according to the given displacement. When the parameter is a positive number, scroll in the forward direction, otherwise it will scroll in the reverse direction
Scroll towards.
15. scrollTo method
Grammar format:
window.scrollTo(x,y)
Function: Scroll the content in the window to the specified position.
16.find method
Grammar format:
window.find()
Function: When this method is triggered, a "find" dialog window will pop up and allow the user to touch
Find a string in the page using the find method.
Note: This attribute is not supported in IE5.5 and Netscape6.0.
17. back method
Grammar format:
window.back()
Function: Simulate the user clicking the "Back" button on the browser to move the page to the previous page of the browser.
Note: This operation can only be performed when the current page has a previous page.
Note: IE5.5 does not support this method, but Netscape6.0 supports it.
18. forward method
Grammar format:
window.forward()
Function: Simulate the user clicking the "Forward" button on the browser to move the page to the next page of the browser.
Note: This operation can only be performed when the next page exists on the current page.
Note: IE5.5 does not support this method, but Netscape6.0 supports it.
19. home method
Grammar format:
window.home()
Function: Simulate the user clicking the "Home" button on the browser to redirect the page to the specified page.
Note: IE5.5 does not support this method, but Netscape6.0 supports it.
20. stop method
Grammar format:
window.stop()
Function: Simulate the user clicking the "Stop" button on the browser to terminate the browser's download operation.
Note: IE5.5 does not support this method, but Netscape6.0 supports it.
21. print method
Grammar format:
window.print()
Function: Simulate the user clicking the "Print" button on the browser and notify the browser to open the print dialog box for printing
Current page.
22. blur method
Grammar format:
window.blur()
Function: Remove focus from the window. Care must be taken when used with the focus method as it may cause focus
Keep moving in and out.
23. focus method
Grammar format:
window.focus()
Function: Make the window focus. Care must be taken when using it with the blur method as it may result in loss of focus
Move in and out.
24. captureEvent method
Grammar format:
window.captureEvent(Event)
window.captureEvent(event1|event2|...|eventn)
Function: Capture all events with specified parameters. Due to the ability to capture events that are handled by the local program itself
, so programmers can freely define functions to handle events. If there are multiple events that need to be captured, each event
Separate them with 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
Grammar format:
window.enableExternalCapture(event)
Function: The enableExternalCapture method is used to capture external events passed in through parameters.
26. disableExternalCapture event
Grammar format:
window.disableExternalCapture()
Function: Cancel the setting of the enableExternalCapture method and terminate the capture of external events.
27. handleEvent event
Grammar format:
window.handleEvent(event)
Function: Event handler that triggers the specified event.
28. releaseEvent event
Grammar format:
window.releaseEvent(event)
window.releaseEvent(event1|event2|...|eventn)
Function: Release the captured events passed in through parameters. These events are generated by
The releasable events set by the window.captureEvent method are the same as captureEvent.
29. routeEvent event
Grammar format:
window.releaseEvent(event)
Function: Transfer all events of the captured type to standard event processing methods for processing, things that can be transferred
The file is the same as captureEvent.
30 scroll event
Grammar format:
window.scroll(X coordinate, Y coordinate)
Function: Move the window to the specified coordinate position.
The window object has the following properties:
1. status attribute
Grammar format:
window.status=string
Function: Set or give the current display information of the status bar in the browser window.
Tip: You can use this property to set the browser window status bar information.
2. statusbar attribute
Grammar format:
window.statusbar.property
Function: The statusbar attribute itself is also an object, used to access its own visible attribute to confirm
Determines whether the status bar is visible.
Note: IE5.5 browser does not support this attribute.
3. statusbar.visible property
Grammar format:
window.statusbar.visible
Function: Check whether the status bar is visible. If it is visible, it returns true, otherwise it returns false.
Note: IE5.5 browser does not support this attribute.
4. defaultstatus attribute
Grammar 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
Grammar format:
window.location=URL
Function: Give the URL information of the current window or specify the URL of the open window.
6. locationbar attribute
Grammar format:
window.locationbar.property
Function: The locationbar attribute can also be regarded as a sub-object. This attribute is used to obtain its own
visible property to determine whether the location bar is visible.
So far, this property has only one subproperty: visible.
Note: IE5.5 does not support this attribute.
7. locationbar.visible property
Grammar format:
window.locationbar.visible
Function: Returns whether the location bar is visible. If it is visible, it returns true, otherwise it returns false.
Note: IE5.5 does not support this attribute.
8. self attribute
Grammar format:
window.self.method
window.self.property
Function: This attribute contains the flag of the current window. Using this attribute, you can ensure that multiple windows are opened
In this case, functions or properties within the current window are correctly called without confusion.
9. name attribute
Grammar format:
window.name=name
Function: Returns the window name, which is given when the window.open() method creates a new window.
In the javascript1.0 version, this attribute can only be used to read the window name, and in
In the javascript1.1 version, you can use this attribute to give a
that was not created using the window.open() method.
The window is given a name.
10. closed attribute
Grammar format:
window.closed
Function: The closed attribute is used to return whether the instance of the specified window has been closed. If closed, return true
, otherwise it returns false.
11. frames attribute
Grammar format:
window.frames["frame name"]
window.frames[numeric]
Function: The frames attribute is an array used to store each sub-window created by an element in the document (frame
Frame) instance, where the subscript can be either a sequence number or a name specified using the NAME attribute of the FRAME element
Scale to get and use.
12. frames.length property
Grammar format:
window.frames.length
Function: The frames.length attribute is used to give the number of sub-window (frame) instances in the document.
13. length attribute
Grammar format:
window.length
Function: The length attribute returns the number of sub-windows in a window. This attribute is the same as
The value of the window.frame.length property is the same.
14. document attribute
Grammar format:
window.document.event
window.document.method
window.document.property
Function: The sub-object document of the window object is the core object of javascript.
is encountered in the script
Create an instance of the BODY element.
15. history attribute
Grammar format:
window.history[numeric]
window.history.method()
window.history.property
The sub-object history of the window object is one of the core objects of JavaScript. This attribute contains a
An array of names and URLs of pages that have been visited.
16. innerHeight property
Grammar format:
window.innerHeight=numeric value
Function: Return or specify the pixel height of the document in the browser window. This height does not include any toolbars and
The height of the page decorations that make up the window.
Note: IE5.5 does not support this attribute.
17. innerWidth property
Grammar format:
window.innerHeight=numeric value
Function: Return or specify the pixel width of the document in the browser window. This width does not include any toolbars and
The width of the page decoration that makes up the window.
Note: IE5.5 does not support this attribute.
18. menubar attribute
Grammar format:
window.menubar.property
Function: The menubar attribute can also be regarded as a sub-object. This attribute is used to obtain its own
visible property to determine whether the menu bar is visible.
So far, this property has only one subproperty: visible.
Note: IE5.5 does not support this attribute.
19. menubar.visible property
Grammar format:
window.menubar.visible
Function: menubar.visible property is used to return whether the menu bar is visible. If it is visible, it returns true, otherwise
It returns false.
Note: IE5.5 does not support this attribute.
20. opener attribute
Grammar format:
window.opener
window.opener.method
window.opener.property
Function: The opener attribute is associated with the parent window that opens the window. When accessing the operer attribute in the child window
, the parent window is returned. This property provides access to methods and properties from the parent window object.
21. outerHeight property
Grammar format:
window.outerHeight
Function: The outerHeight property is used to access the pixel height of the browser window, which includes the toolbar and
The height of the decorative edge.
Note: IE5.5 does not support this attribute.
22. outerWidth attribute
Grammar format:
window.outerWidth
Function: The outerWidth attribute is used to access the pixel width of the browser window, which includes toolbars and devices
The width of the trim.
Note: IE5.5 does not support this attribute.
23. pageXOffset attribute
Grammar format:
window.pageXOffset=numeric value
Function: Specify the current horizontal pixel position of the upper left corner of the document in the browser window in the window. Using
Before movingTo, you can use this property to decide whether the window needs to be moved. Because this attribute returns
The current position of the visible document relative to the entire page.
Note: IE5.5 does not support this attribute.
24. pageYOffset attribute
Grammar format:
window.pageYOffset=numeric value
Function: Specify the current vertical pixel position of the upper left corner of the document in the browser window in the window. Using
Before movingTo, you can use this property to decide whether the window needs to be moved. Because this attribute returns
The current position of the visible document relative to the entire page.
Note: IE5.5 does not support this attribute.
25. parent attribute
Grammar format:
window.parent.frames[numeric]
window.parent.framesName
Function: Access the parent window where each child window (multi-frame) is located.
26. personalbar attributes
Grammar format:
window.personalbar.property
Function: The personalbar attribute itself is also an object, which is used to access its own visible attribute to confirm
Determine whether the personal column is visible.
Note: IE5.5 does not support this attribute.
27. personalbar.visible property
Grammar format:
window.personalbar.visible
Function: Determine whether the personal column is visible. If it is visible, it returns true, otherwise it returns false.
Note: IE5.5 does not support this attribute.
28. scrollbars properties
Grammar format:
window.scrollbars.property
Function: The scrollbars attribute itself is also an object, which is used to access its own visible attribute to confirm
Determines whether the scroll bar is visible.
Note: IE5.5 does not support this attribute.
29. scrollbars.visible property
Grammar format:
window.scrollbars.visible
Function: scrollbars.visible is used to determine whether the scroll bar is visible. If it is visible, it returns true, otherwise
It returns false.
Note: IE5.5 does not support this attribute.
30. toolbar attribute
Grammar format:
window.toolbar.property
Function: The toolbar attribute itself 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 property
Grammar format:
window.toolbar.visible
Function: toolbar.visible property is used to check whether the toolbar is visible, and returns true if visible,
Otherwise, return false.
Note: IE5.5 does not support this attribute.
32. top attribute
Grammar format:
window.top.frames[numeric]
window.top.frameName
window.top.method()
window.top.property
Function: The top attribute of the window object is used to contain information about the top-most window of all sub-windows (multi-frames) loaded into the browser.
The above is the entire content of this article, I hope you all like it.