English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Window Object (Window Object) represents the window in the browser. The Window Object (Window Object) is automatically created by the browser.
The window is a browser object, not a JavaScript object. JavaScript objects are strings, arrays, dates, etc.
Note:If the HTML document contains frames or iframes, the browser will create other Window Objects (Window Object) for each frame.
All global variables are properties, and functions are methods of the Window Object (Window Object).
ThisDocumentThe object is a property of the Window Object. Therefore, entering
window.document.write("Hello world")
Is equivalent to:
document.write("Hello world")
The following table lists the properties of the Window object:
Property | Description |
---|---|
closed | Indicates whether the current window is closed |
console | Returns a reference to the specified console object, which provides access to the browser's debugging console (See the Console object) |
defaultStatus | Sets or returns the status bar text of the given window |
document | Returns a reference to the document contained in the window (See the Document object) |
frameElement | Returns the <iframe> element that inserted the current window |
frames | Returns all <iframe> elements in the current window |
history | Returns a reference to the history object associated with the window (See the History object) |
innerHeight | Returns the height of the window content area (viewport) containing the scroll bar |
innerWidth | Returns the width of the window content area (viewport) containing the scroll bar |
length | Returns the number of <iframe> elements in the current window |
localStorage | Allows the key/The value pair is stored in the web browser. The data stored without an expiration date |
location | Returns a reference to the location object associated with the window (See Location Object) |
name | Sets or returns the window name |
navigator | Returns a reference to the navigator object associated with the window (See Navigator Object) |
opener | Returns a reference to the window that created the window |
outerHeight | Returns the height of the browser window, including the toolbar/Scrollbar |
outerWidth | Returns the width of the browser window, including the toolbar/Scrollbar |
pageXOffset | Returns the number of pixels the document has been scrolled horizontally |
pageYOffset | Returns the number of pixels the document has been scrolled vertically |
parent | Returns the parent window of the current window |
screen | Returns a reference to the screen object associated with the window(See Screen Object) |
screenLeft | Returns the horizontal coordinate of the window relative to the screen |
screenTop | Returns the vertical coordinate of the window relative to the screen |
screenX | screenLeftalias |
screenY | screenTopalias |
scrollX | pageXOffsetalias |
scrollY | pageYOffsetalias |
sessionStorage | Allows the key/Pairs are stored in web browsers. Stores session data |
self | Returns a reference to the Window Object (Window Object) itself |
status | Sets or returns the text in the window status bar |
top | Returns a reference to the top-level window in the window hierarchy |
The following table lists the methods of the Window object:
Method | Description |
---|---|
alert() | Displays an alert box with a message and an 'OK' button |
atob() | Decode base-64Encoded string |
blur() | Removes the focus from the current window |
btoa() | In base-64Encode a string |
clearInterval() | Clears the timer set using setInterval() |
clearTimeout() | Clears the timer set using setTimeout() |
close() | Closes the current window |
confirm() | Displays a dialog box containing a message that the user needs to respond to |
focus() | Sets the focus to the current window |
getComputedStyle() | Retrieves the current computed CSS style applied to the element |
getSelection() | Returns a Selection object representing the text range selected by the user |
matchMedia() | Returns a MediaQueryList object representing the specified media query string |
moveBy() | Move the window relative to the current position |
moveTo() | Move the window to the specified position |
open() | Open a new browser window |
print() | Print the content of the current window |
prompt() | Display a dialog box to prompt the visitor to enter |
requestAnimationFrame() | Request the browser to call a function to update the animation before the next repaint |
resizeBy() | Adjust the window size by a specified number of pixels |
resizeTo() | Adjust the window to the specified width and height |
scroll() | Not recommended for use.This method has been replaced byscrollTo()Method instead. |
scrollBy() | Scroll the document by a specified number of pixels |
scrollTo() | Scroll the document to the specified coordinates |
setInterval() | Call a function or execute a code block at a specified time interval (in milliseconds) |
setTimeout() | Call a function or execute a code block after a specified number of milliseconds |
stop() | Stop Loading Window |