HTML DOM Window 对象
Window 对象
Window 对象用于描述浏览器窗口. A Window object is created automatically with every instance of a <body> or <frame> tag.
IE: Internet Explorer, F: Firefox, N: Netscape, W3C: World Wide Web Consortium (Internet Standard).
Window 对象集合
集合 | 说明 | IE | F | N | W3C |
---|---|---|---|---|---|
frames[] | 返回所有在window中已经命名的frame | 3 | 1 | 2 |
对象名 | 说明 | IE | F | N | W3C |
---|---|---|---|---|---|
clientInformation | 包含了有关浏览器的信息 | 4 | |||
clipboardData | 包含了系统剪贴板的有关数据信息 | 5 | |||
document | 这个对象可用于访问页面中的所有元素 | 3 | |||
event | 描述某一事件状态 | 4 | |||
external | 4 | ||||
history | 包含了用户曾经用浏览器访问过的URL | 3 | |||
location | 包含了当前浏览器地址栏中的URL | 3 | |||
navigator | 包含了客户端浏览器的相关信息 | 3 | |||
screen | 包含了客户端显示屏的相关信息 | 4 |
Window 对象属性
属性名 | 说明 | IE | F | N | W3C |
---|---|---|---|---|---|
closed | 返回所引用窗口是否关闭的boolean型值 | 4 | 1 | 3 | |
defaultStatus | 设置或返回浏览器窗口状态栏的缺省文本(在页面载入时显示) | 3 | 1 | 2 | |
dialogArguments | 返回所有传递到模式对话框窗口中的参数 | 4 | |||
dialogHeight | 设置或返回模式对话框窗口的高度 | 4 | |||
dialogLeft | 设置或返回模式对话框窗口距屏幕左边界的距离(单位为像素) | 4 | |||
dialogTop | 设置或返回模式对话框窗口距屏幕顶部边界的距离(单位为像素) | 4 | |||
dialogWidth | 设置或返回模式对话框窗口的宽度 | 4 | |||
frameElement | 返回 frame 或 iframe 对象所在父文档的窗口 | 5 | |||
length | 设置或返回窗口中包含的frame的数量 | 4 | 1 | 6 | |
name | 设置或返回窗口的名称 | 3 | 1 | 2 | |
offscreenBuffering | 设置或获取对象在对用户可见之前是否要先在屏幕外绘制 | 4 | |||
opener | 设置或获取创建当前窗口的窗口的引用 | 4 | 1 | 3 | |
parent | 获取对象层次中的父窗口 | 3 | 1 | 2 | |
returnValue | 设置或获取从模式对话框返回的值 | 4 | |||
screenLeft | 获取浏览器客户端左上角相对于屏幕左上角的 x 坐标 | 5 | |||
screenTop | 获取浏览器客户端左上角相对于屏幕左上角的 y 坐标 | 5 | |||
self | 返回对当前窗口的引用 | 3 | 1 | 2 | |
status | 设置或获取位于窗口底部状态栏的信息 | 3 | 1 | 2 | |
top | 获取最顶层的祖先窗口 | 3 | 1 | 2 |
Window 对象方法
方法 | 说明 | IE | F | N | W3C | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
alert() | 显示一个带有指定信息和确定按钮的警告对话框 | 3 | 1 | 2 | |||||||||||||||||||||||||
attachEvent("event",pointer) | 5 | ||||||||||||||||||||||||||||
blur() | 将焦点从当前窗口移除 | 4 | 1 | 3 | |||||||||||||||||||||||||
clearInterval(ID) | 取消由setInterval() 方法设置的timeout时间 | 4 | 1 | 4 | |||||||||||||||||||||||||
clearTimeout(ID) | 取消由setTimeout()方法设置的timeout时间 | 3 | 1 | 2 | |||||||||||||||||||||||||
close() | 关闭当前窗口 | 3 | 1 | 2 | |||||||||||||||||||||||||
confirm() | 显示一个带有指定信息和确定、取消按钮的对话框 | 3 | 1 | 2 | |||||||||||||||||||||||||
createPopup() | 创建弹出窗口 | 5 | |||||||||||||||||||||||||||
execScript("code", "lang") | 执行指定的脚本, 参数说明如下:
| 4 | |||||||||||||||||||||||||||
focus() | 设这当前窗口的焦点位置 | 4 | 1 | 3 | |||||||||||||||||||||||||
moveBy(x,y) | 将当前窗口移动指定大小个像素位置(相对当前位置) | 4 | 1 | 4 | |||||||||||||||||||||||||
moveTo(x,y) | 将当前窗口移动到指定位置(绝对位置) | 4 | 1 | 4 | |||||||||||||||||||||||||
navigate("URL") | 载入指定的URL到当前窗口 | 3 | |||||||||||||||||||||||||||
open() | 打开一个新浏览窗口 | 3 | |||||||||||||||||||||||||||
print() | 打印当前窗口的内容 | 5 | 1 | 4 | |||||||||||||||||||||||||
prompt() | 显示一个提示用户输入的对话框 | 3 | 1 | 2 | |||||||||||||||||||||||||
resizeBy() | 缩放当前窗口指定个像素大小(相对缩放) | 4 | |||||||||||||||||||||||||||
resizeTo() | 缩放当前窗口到指定大小(绝对缩放) | 4 | 1.5 | ||||||||||||||||||||||||||
scroll() | (不推荐使用). 使用 scrollTo() 来代替 | 4 | |||||||||||||||||||||||||||
scrollBy() | 滚动当前窗口内容指定个像素位置(相对滚动) | 4 | 1 | 4 | |||||||||||||||||||||||||
scrollTo() | 滚动当前窗口内容到指定像素位置(绝对滚动) | 4 | 1 | 4 | |||||||||||||||||||||||||
setActive() | 5 | ||||||||||||||||||||||||||||
setInterval(code, millisec[, "lang"]) | 在指定时间间隔内执行指定的代码,参数含义如下:
| 4 | 1 | 4 | |||||||||||||||||||||||||
setTimeout() | 在指定时间后调用一个函数或一段代码 | 3 | 1 | 2 | |||||||||||||||||||||||||
showHelp("URL"[, contextID]) | 显示一个帮助文件 (必须是.htm或.chm格式). 使用此方法时,当用户点击F1或点击菜单栏上的帮助时会弹出一个帮助窗口, 为防止出现默认的帮助窗口应该设置返回值为false, 参数含义如下
| 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: "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: "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.
Window Object Events
Syntax: 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 |