English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Window-Objekt

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")

Window Object (Window Object) Properties

The following table lists the properties of the Window object:

Property描述
closedIndicates whether the current window is closed
consoleReturns a reference to the specified console object, which provides access to the browser's debugging console (See the Console object
defaultStatusSets or returns the status bar text of the given window
documentReturns a reference to the document contained in the window (See the Document object
frameElementReturns the <iframe> element that inserted the current window
framesReturns all <iframe> elements in the current window
historyReturns a reference to the history object associated with the window (See the History object
innerHeightReturns the height of the window content area (viewport) that includes the scroll bar
innerWidthReturns the width of the window content area (viewport) that includes the scroll bar
lengthReturns 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返回窗口相对于屏幕的垂直坐标
screenXscreenLeft的别名
screenYscreenTop的别名
scrollXpageXOffset的别名
scrollYpageYOffset的别名
sessionStorage允许将键/值对保存在Web浏览器中。存储一个会话的数据
self返回对窗口对象(Window Object)本身的对象引用
status设置或返回窗口状态栏中的文本
top返回对窗口层次结构中最顶层窗口的引用

窗口对象(Window Object)方法

下表列出了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