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 an object of the browser, 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, input
window.document.write("Hello world")
Is equivalent to:
document.write("Hello world")
The following table lists the properties of the Window object:
Property | 描述 |
---|---|
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) that includes the scroll bar |
innerWidth | Returns the width of the window content area (viewport) that includes the scroll bar |
length | Returns the number of <iframe> elements in the current window |
localStorage | 允许将键/Value pairs are stored in the web browser. Data stored without an expiration date |
location | 返回对与窗口关联的位置对象的引用(请参见Location对象) |
name | 设置或返回窗口名称 |
navigator | 返回对与窗口关联的导航器对象的引用(请参见Navigator对象) |
opener | 返回对创建该窗口的窗口的引用 |
outerHeight | 返回浏览器窗口的高度,包括工具栏/滚动条 |
outerWidth | 返回浏览器窗口的宽度,包括工具栏/滚动条 |
pageXOffset | 返回文档已经水平滚动的像素数 |
pageYOffset | 返回文档已经垂直滚动的像素数 |
parent | 返回当前窗口的父窗口 |
screen | 返回对与窗口关联的屏幕对象的引用(请参见Screen对象) |
screenLeft | 返回窗口相对于屏幕的水平坐标 |
screenTop | 返回窗口相对于屏幕的垂直坐标 |
screenX | screenLeft的别名 |
screenY | screenTop的别名 |
scrollX | pageXOffset的别名 |
scrollY | pageYOffset的别名 |
sessionStorage | 允许将键/值对保存在Web浏览器中。存储一个会话的数据 |
self | 返回对窗口对象(Window Object)本身的对象引用 |
status | 设置或返回窗口状态栏中的文本 |
top | 返回对窗口层次结构中最顶层窗口的引用 |
下表列出了Window对象的方法:
方法 | 描述 |
---|---|
alert() | 显示带有消息和“确定”按钮的警报框 |
atob() | 解码base-64编码的字符串 |
blur() | 从当前窗口移开焦点 |
btoa() | 在base-64对字符串进行编码 |
clearInterval() | 清除使用setInterval()设置的计时器 |
clearTimeout() | 清除使用setTimeout()设置的计时器 |
close() | 关闭当前窗口 |
confirm() | 显示一个对话框,其中包含用户需要响应的消息 |
focus() | 将焦点设置到当前窗口 |
getComputedStyle() | 获取应用于元素的当前计算的CSS样式 |
getSelection() | 返回表示用户选择的文本范围的Selection对象 |
matchMedia() | 返回表示指定媒体查询字符串的MediaQueryList对象 |
moveBy() | Fenster vom aktuellen Standort aus bewegen |
moveTo() | Fenster an angegebene Position bewegen |
open() | Neues Browserfenster öffnen |
print() | Inhalt des aktuellen Fensters drucken |
prompt() | Ein Dialogfeld anzeigen, um dem Besucher die Eingabe zu ermöglichen |
requestAnimationFrame() | Browser auffordern, die Funktion vor dem nächsten Rerendering aufzurufen, um die Animation zu aktualisieren |
resizeBy() | Fenstergröße um angegebene Pixel anpassen |
resizeTo() | Fenster auf angegebene Breite und Höhe anpassen |
scroll() | Nicht empfohlen.Diese Methode wurde durchscrollTo()Methode ersetzen. |
scrollBy() | Dokument um angegebene Pixel rollen |
scrollTo() | Dokument auf angegebene Koordinaten rollen |
setInterval() | Funktion oder Code-Abschnitt mit angegebenem Zeitintervall (in Millisekunden) aufrufen oder ausführen |
setTimeout() | Funktion oder Code-Abschnitt nach angegebener Millisekunden-Zeit aufrufen oder ausführen |
stop() | Lade Fenster stoppen |