当前位置: 首页 > 网络学院 > 客户端脚本教程 > HTML DOM > DOM Window 对象
The Window object represents the browser window. A Window object is created automatically with every instance of a <body> or <frame> tag.
window对象代表了浏览器的窗口。每当窗口含有<body>或是<frame>标签就会自动建立window对象
IE: Internet Explorer, F: Firefox, N: Netscape, W3C: World Wide Web Consortium (Internet Standard).
Collection 集合 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
frames[] | Returns all named frames in the window 返回在window中所有命名过的框架 | 3 | 1 | 2 |
Object | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
clientInformation | Contains information about the browser 包含有关浏览器的信息 | 4 | |||
clipboardData | 5 | ||||
document | This object can be used to access all elements in a page 这个对象可以用来访问在页面中的所有元素 | 3 | |||
event | Represents the state of an event 某个事件的状态 | 4 | |||
external | 4 | ||||
history | Contains the URLs the user has visited within a browser window 包含用户在浏览器窗口中所有已经访问过的URL | 3 | |||
location | Contains the current URL of the window 包含了当前窗口的URL | 3 | |||
navigator | Contains information about the client browser 包含了有关客户端浏览器的信息 | 3 | |||
screen | Contains information about the client's display screen 包含了有关客户端显示屏幕的信息 | 4 |
Property 属性 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
closed | Returns a Boolean value that specifies whether the referenced window has been closed 获取引用窗口是否已关闭。 | 4 | 1 | 3 | |
defaultStatus | Sets or returns the default text in the statusbar of the windows (will be displayed when the page loads) 设置或获取要在窗口底部的状态栏上显示的缺省信息。 | 3 | 1 | 2 | |
dialogArguments | Returns all variables passed into the modal dialog window 设置或获取传递给模式对话框窗口的变量或变量数组。 | 4 | |||
dialogHeight | Sets or returns the height of the modal dialog window 设置或获取模式对话框的高度。 | 4 | |||
dialogLeft | Sets or returns the left coordinates of the modal dialog window 设置或获取模式对话框的左坐标。 | 4 | |||
dialogTop | Sets or returns the top coordinates of the modal dialog window 设置或获取模式对话框的顶坐标。 | 4 | |||
dialogWidth | Sets or returns the width of the modal dialog window 设置或获取模式对话框的宽度。 | 4 | |||
frameElement | Returns the frame/iframe object that is hosting the window in the parent document 获取在父文档中生成 window 的 frame 或 iframe 对象。 | 5 | |||
length | Sets or returns the number of frames in the window 设置或获取集合中对象的数目。 | 4 | 1 | 6 | |
name | Sets or returns the name of the window 设置或获取表明窗口名称的值。 | 3 | 1 | 2 | |
offscreenBuffering | Sets or returns a Boolean value that specifies whether the window is drawn offscreen before being visible to the user 设置或获取对象在对用户可见之前是否要先在屏幕外绘制。 | 4 | |||
opener | Sets or returns a reference to the window that created the window 设置或获取创建当前窗口的窗口的引用。 | 4 | 1 | 3 | |
parent | Returns the parent window 获取对象层次中的父窗口。 | 3 | 1 | 2 | |
returnValue | Sets or returns the value returned from the modal dialog window 设置或获取从模式对话框返回的值。 | 4 | |||
screenLeft | Returns the x-coordinate of the upper left corner of the browser - relative to the upper left corner of the screen 获取浏览器客户区左上角相对于屏幕左上角的 x 坐标。 | 5 | |||
screenTop | Returns the y-coordinate of the top corner of the browser - relative to the top corner of the screen 获取浏览器客户区左上角相对于屏幕左上角的 y 坐标。 | 5 | |||
self | Returns a reference to the current window 获取对当前窗口或框架的引用。 | 3 | 1 | 2 | |
status | Sets or returns the text in the statusbar of the window 设置或获取位于窗口底部状态栏的信息。 | 3 | 1 | 2 | |
top | Returns the topmost ancestor window 获取最顶层的祖先窗口。 | 3 | 1 | 2 |
Method 方法 | Description 描述 | IE | F | N | W3C | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
alert() | Displays an alert box with a specified message and an OK button 显示包含由应用程序自定义消息的对话框。 | 3 | 1 | 2 | |||||||||||||||||||||||||
attachEvent("event",pointer) | 将指定函数绑定到事件,以便每当该事件在对象上触发时都调用该函数。 | 5 | |||||||||||||||||||||||||||
blur() | Removes focus from the current window 使元素失去焦点并触发 onblur 事件。 | 4 | 1 | 3 | |||||||||||||||||||||||||
clearInterval(ID) | Cancels a timeout that is set with the setInterval() method 取消由setInterval()建立的间隔事件 | 4 | 1 | 4 | |||||||||||||||||||||||||
clearTimeout(ID) | Cancels a timeout that is set with the setTimeout() method 取消由setTimeout()方法建立的间隔事件 | 3 | 1 | 2 | |||||||||||||||||||||||||
close() | Closes the current window 关闭当前浏览器窗口 | 3 | 1 | 2 | |||||||||||||||||||||||||
confirm() | Displays a dialog box with a specified message and an OK and a Cancel button 显示一个确认对话框,其中包含一个可选的消息和确定取消按钮。 | 3 | 1 | 2 | |||||||||||||||||||||||||
createPopup() | Creates a pop-up window 创建弹出窗口。 | 5 | |||||||||||||||||||||||||||
execScript("code", "lang") | Executes a specified script. The arguments can take the following values:
| 4 | |||||||||||||||||||||||||||
focus() | Sets focus on the current window 聚焦到当前的窗口 | 4 | 1 | 3 | |||||||||||||||||||||||||
moveBy(x,y) | Moves the window a specified number of pixels in relation to its current co-ordinates 将窗口的位置移动指定 x 和 y 偏移值。 | 4 | 1 | 4 | |||||||||||||||||||||||||
moveTo(x,y) | Moves the window's left and top edge to the specified co-ordinates 将窗口左上角的屏幕位置移动到指定的 x 和 y 位置。 | 4 | 1 | 4 | |||||||||||||||||||||||||
navigate("URL") | Loads the specified URL into the window 在当前窗口中装入指定 URL。 | 3 | |||||||||||||||||||||||||||
open() | Opens a new browser window 打开新窗口并装入给定 URL 的文档。 | 3 | |||||||||||||||||||||||||||
print() | Prints the contents of the current window 打印与窗口关联的文档。 | 5 | 1 | 4 | |||||||||||||||||||||||||
prompt() | Displays a dialog box that prompts the user for input | 3 | 1 | 2 | |||||||||||||||||||||||||
resizeBy() | Resizes the window by the specified pixels 更改窗口的当前位置缩放指定的 x 和 y 偏移量。 | 4 | |||||||||||||||||||||||||||
resizeTo() | Resizes the window to the specified width and height 将窗口的大小更改为指定的宽度和高度值。 | 4 | 1.5 | ||||||||||||||||||||||||||
scroll() | Deprecated. Use scrollTo() instead 将窗口滚动到自左上角起指定的 x 和 y 偏移量。 | 4 | |||||||||||||||||||||||||||
scrollBy() | Scrolls the content by the specified number of pixels 将窗口滚动 x 和 y 偏移量。 | 4 | 1 | 4 | |||||||||||||||||||||||||
scrollTo() | Scrolls the content to the specified coordinates 将窗口滚动到指定的 x 和 y 偏移量。 | 4 | 1 | 4 | |||||||||||||||||||||||||
setActive() | 设置对象为当前对象而不将对象置为焦点。 | 5 | |||||||||||||||||||||||||||
setInterval(code, millisec[, "lang"]) | Calls a function / evaluate an expression every time a specified interval (in milliseconds) has been reached. The arguments can take the following values:
| 4 | 1 | 4 | |||||||||||||||||||||||||
setTimeout() | Calls a function or evaluates an expression after a specified number of milliseconds | 3 | 1 | 2 | |||||||||||||||||||||||||
showHelp("URL"[, contextID]) | Displays a Help file (must be of type .htm or .chm). When using this method, a second Help box appears when pressing F1 or when clicking Help on the menu bar. To prevent the default Help box from appearing set returnValue to false. The arguments can take the following values:
| 4 | |||||||||||||||||||||||||||
showModalDialog("URL"[, args, "list"]) | Loads a URL in a modal dialog box. A modal dialog box retains focus while open. The user CANNOT switch windows until the dialog box is closed. The arguments can take the following values: 创建一个显示指定 HTML 文档的模式对话框。 "URL" - Required. The URL of the document to display. args - Optional. The arguments to use when displaying the URL. Use this parameter to pass a value of any type, including an array of values. The dialog box can extract the values from the dialogArguments property of the window object. "list" - Optional. Specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:
| 4 | |||||||||||||||||||||||||||
showModelessDialog("URL"[, args, "list"]) | Loads a URL in a modeless dialog box. The modeless dialog box displays even when the user switches focus to another window (useful for menus and Help systems). The arguments can take the following values: 创建一个显示指定 HTML 文档的非模式对话框。 "URL" - Required. The URL of the document to display. args - Optional. The arguments to use when displaying the URL. Use this parameter to pass a value of any type, including an array of values. The dialog box can extract the values from the dialogArguments property of the window object. "list" - Optional. Specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:
| 5 |
* The default unit of measure for dialogHeight and dialogWidth in IE4 is em; in IE5 it is px. Other values to use: cm, mm, in, pt, pc, or ex. For consistent results, use px! Note: The min. dialogHeight you can specify is 100px.
在IE4中dialogHeight 和dialogWidth的默认单位是em。在IE5为px。其它的单位会混淆结果,最好用px! 注意:dialogHeight的最小值为100px
语法 window.event_name="someJavaScriptCode"
Event 事件 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
onBlur | Executes some code when a Blur event occurs 在对象失去输入焦点时触发。 | 1 | 3 | ||
onError | Executes some code when an Error event occurs 当对象装载过程中发生错误时触发。 | 1 | 3 | ||
onFocus | Executes some code when a Focus event occurs 当对象获得焦点时触发。 | 1 | 3 | ||
onLoad | Executes some code when an Load event occurs 在浏览器完成对象的装载后立即触发。 | 1 | 2 | ||
onResize | Executes some code when a Resize event occurs 当对象的大小将要改变时触发。 | 1 | 4 | ||
onUnload | Executes some code when an Unload event occurs 在对象卸载前立即触发。 | 1 | 2 |