窗口对象的属性
window 对象是 DOM 层次结构的最顶层对象。它表示显示网页内容的浏览器窗口或框架。每当屏幕上出现一个显示文档内容的窗口时,就会创建窗口对象。 Window对象常用的属性和方法如下表所示:
窗口对象的属性
Property Name | Purpose |
---|---|
Closed | It holds a Boolean value that represents whether the window is closed or not. |
console | It returns a reference to the console object which provides access to the browser’s debugging console. |
defaultStatus | It is used to define the default message that will be displayed in the status bar when no activity is carried on by the browser. |
controllers | It returns the XUL controller objects for the current Chrome window. |
customElements | It returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and also get information about already registered custom elements. |
crypto | It returns the browser crypto object. |
devicePixelRatio | It returns the ratio between physical pixels and device independent pixels in the current display. |
Document | It returns a reference to the document object of that window. |
DOMMatrix | It returns a reference to a DOMMatrix object, which represents 4×4 matrices, suitable for 2D and 3D operations. |
frames[] | It represents an array that contains all the frames of a given window. |
DOMPoint | It returns a reference to a DOMPoint object, which represents a 2D or 3D point in a coordinate system. |
History | It provides information of the URLs visited in the current window. |
Length | It represents the number of frames in the current window. |
DOMRect | It returns a reference to a DOMRect object, which represents a rectangle. |
fullScreen | This property indicates whether the window is displayed in full screen or not. |
Location | It contains the URL of the current window. |
innerHeight | It is used to get the height of the content area of the browser window. |
innerWidth | It is used to get the width of the content area of the browser window. |
Name | It contains name of the referenced window. |
Opener | It contains a reference to the window that opened the current window. |
Parent | It refers to the frame set in which the current frame is contained. |
Screen | It refers to the screen object |
Self | It provides another way to refer the current window. |
Status | It overrides the defaultStatus and places a message in the status bar. |
Top | It returns a reference to the topmost window containing a frame if many windows are opened. |
Window | It returns the current window or frame. |
Navigator | It returns a reference to the navigator object. |
outerHeight | It will get height of the outside of the browser window. |
outerWidth | It will get width of the outside of the browser window. |
Toolbar | It will result the toolbar object, whose visibility can be toggled in the window. |
要访问窗口对象的属性,您将指定对象名称,后跟句号 (.) 和属性名称。
句法:
window.property_name
例子:
HTML
输出:
点击按钮前:
点击按钮后: