Home > Article > Web Front-end > Compilation of information related to js window object properties and methods_javascript skills
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 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 opening a new browser window, the open method can also specify the name of the window (the second parameter);
When opening a new browser window, the open method can also specify the style of the window (the third parameter). The window style has the following options. These options can be multiple selected. If multiple selections are made, use commas between each option. Separator:
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: Specify 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, which has been 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: Specify 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.
Tips: This method is often used to automatically open another window when opening a web page.
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: Pop up a warning box and display the prompt string text in the warning box.
4. confirm method
Syntax format: window.confirm(prompt string)
Function: Display a confirmation box and display a prompt string in the confirmation box. This method returns true when the user clicks the "OK" button and returns false when the user clicks "Cancel".
5. prompt method
Syntax format: window.prompt (prompt string, default text)
Function: Display an input box, display the prompt string in the input box, display the default text in the input text box, and wait for user input. When the user clicks the "OK" button, return the string entered by the user. When the Cancel button is clicked, a null value is returned.
6. setTimeout method
Syntax format: window.setTimeout(code character expression, milliseconds)
Function: Timing setting, automatically execute the code character expression after the specified number of milliseconds.
7. clearTimeout method
Syntax format: window.clearTimeout(timer)
Function: Cancel the previous timing setting. The parameter is the return value when set with setTimeout.
8. setInterval method
Syntax 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
Syntax 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
Syntax 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, and the second parameter is the pixel by which the window is moved vertically.
11.moveTo method
Syntax format: window.moveTo(x,y)
Function: Move the window to the specified specified coordinates (x, y).
12. resizeBy method
Syntax 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, it is reduced.
13. resizeTo method
Syntax 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
Syntax format: window.scrollBy(horizontal displacement, vertical displacement)
Function: Scroll the content in the window by a given displacement. When the parameter is a positive number, scroll forward, otherwise scroll in the reverse direction.
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 window will pop up and allow the user to find a string in the page that triggered the find method.
Note: This attribute is not supported in IE5.5 and Netscape6.0.
17. back method
Syntax 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 does.
18. forward method
Syntax 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 does.
19. home method
Syntax 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 does.
20. stop method
Syntax 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 does.
21. print method
Syntax format: window.print()
Function: Simulate the user clicking the "Print" button on the browser to notify the browser to open the print dialog box and print the current page.
22. blur method
Syntax format: window.blur()
Function: Remove focus from the window. Care must be taken when used with the focus method, as this may cause the focus to continually move in and out.
23. focus method
Syntax format: window.focus()
Function: Make the window focus. Be careful when using it with the blur method as it may cause focus to move in and out
24. captureevent method
Syntax format: window.captureevent(event)
window.captureevent(event1|event2|…|eventn)
Function: Capture all events with specified parameters. Because of the ability to capture events that are handled by the local program itself, programmers can freely define functions to handle events. If there are multiple events that need to be captured, use the pipe character "|" to separate each event. The event types that can be captured are as follows:
event.abortevent.blurevent.changeevent.clickevent.dblclickevent.dragdropevent.errorevent.focusevent.keydownevent.keypressevent.keyupevent.loadevent.mousedownevent.mousuemoveevent.mouseoutevent. 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: Cancel the setting of the enableexternalcapture method and terminate the capture of external events.
27. handleevent event
Syntax format: window.handleevent(event)
Function: Event handler that triggers the specified event.
28. releaseevent event
Syntax format: window.releaseevent(event)
window.releaseevent(event1|event2|…|eventn)
Function: Release the captured events passed in through parameters. These events are set by the window.captureevent method. The releasable events are the same as captureevent.
29. routeevent event
Syntax format: window.releaseevent(event)
Function: Transfer all events of the captured type to standard event processing methods for processing. The events that can be transferred are the same as captureevent.
30. scroll event
Syntax format: window.scroll(x coordinate, y coordinate)
Function: Move the window to the specified coordinate position.
Properties of window object
The window object has the following properties:
status statusbar statusbar.visible defaultstatus location locationbar locationbar.visible self name closed frames frames.length document history innerheight innerwidth menubar menubar.visible opener outerheight outerwidth pagexoffset pageyoffset parent personalbar personalbar.visiblescrollbar scroll bar.visible toolbar toolbar.visible top
1. status attribute
Syntax format: window.status=string
Function: Set or give the current display information of the status bar in the browser window.
Tips: You can use this attribute to set the browser window status bar information.
2. statusbar attribute
Syntax format: window.statusbar.Attribute
Function: The statusbar attribute itself is also an object, used to access its own visible attribute to determine whether the status bar is visible.
Note: IE5.5 browser does not support this attribute.
3. statusbar.visible property
Syntax 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
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: Give the url information of the current window or specify the url of the open window.
6. locationbar attribute
Syntax 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 attribute 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
Syntax 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
Syntax format: window.self.method
window.self.Property
Function: This attribute contains the flag of the current window. Using this attribute, you can ensure that when multiple windows are opened, the functions or properties in the current window are correctly called without confusion.
9. name attribute
Syntax format: window.name=name
Function: Returns the window name, which is given when the window.open() method creates a new window. In the JavaScript 1.0 version, this attribute can only be used to read the window name. In the JavaScript 1.1 version, you can use this attribute to specify a name for a window that is not created using the window.open() method.
10. closed attribute
Syntax format: window.closed
Function: The closed attribute is used to return whether the instance of the specified window has been closed. If it is closed, it returns true, otherwise it returns false.
11. frames attribute
Syntax format: window.frames["frame name"]
window.frames[numeric]
Function: The frames attribute is an array, used to store each sub-window (frame) instance created by an element in the document. The subscript can be the sequence number or the name specified by the name attribute of the frame element. to get and use.
12. frames.length property
Syntax 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
Syntax format: window.length
Function: The length attribute returns the number of sub-windows in a window. This attribute has the same value as the window.frame.length attribute.
14. document attribute
Syntax 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. An instance is created when the body element is encountered in the script.
15. history attribute
Syntax format: window.history[value] 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 an array of the names and URLs of the pages that have been visited.
16. innerheight property
Syntax format: window.innerheight=numeric value
Function: Return or specify the pixel height of the document in the browser window. This height does not include the height of any toolbars and page modifications that make up the window.
Note: IE5.5 does not support this attribute.
17. innerwidth attribute
Syntax format: window.innerheight=numeric value
Function: Return or specify the pixel width of the document in the browser window. This width does not include the width of any toolbars and page modifications that make up the window.
Note: IE5.5 does not support this attribute.
18. menubar attribute
Syntax format: window.menubar.Attribute
Function: The menubar attribute can also be regarded as a sub-object. This attribute is used to obtain its own visible attribute 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
Syntax format: window.menubar.visible
Function: The 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
Syntax 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 attribute
Syntax format: window.outerheight
Function: The outerheight attribute is used to access the pixel height of the browser window, which includes the height of toolbars and decorative edges.
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 width of toolbars and decorative edges.
Note: IE5.5 does not support this attribute.
23. pagexoffset attribute
Syntax 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. Before using moveto to move, you can use this property to decide whether the window needs to be moved. Because this property returns the current position of the visible document relative to the entire page.
Note: IE5.5 does not support this attribute.
24. pageyoffset attribute
Syntax 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. Before using moveto to move, you can use this property to decide whether you need to move the window. Because this property returns the current position of the visible document relative to the entire page.
Note: IE5.5 does not support this attribute.
25. parent attribute
Syntax format: window.parent.frames[numeric] window.parent.framesname
Function: Access the parent window where each child window (multi-frame) is located.
26. personalbar attributes
Syntax format: window.personalbar.property
Function: The personalbar attribute itself is also an object, which is used to access its own visible attribute to determine whether the personal bar is visible.
Note: IE5.5 does not support this attribute.
27. personalbar.visible property
Syntax 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
Syntax format: window.scrollbars.property
Function: The scrollbars property itself is also an object, used to access its own visible property to determine whether the scroll bar is visible
Note: IE5.5 does not support this attribute.
29. scrollbars.visible property
Syntax 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
Syntax 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
Syntax format: window.toolbar.visible
Function: The toolbar.visible property is used to check whether the toolbar is visible. If it is visible, it returns true, otherwise it returns false.
Note: IE5.5 does not support this attribute.
32. top attribute
Syntax 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 topmost window of all sub-windows (multi-frames) loaded into the browser.