Window 对象

来源:互联网 发布:曲率引擎 知乎 编辑:程序博客网 时间:2024/04/20 00:24

Window 对象

原文地址:http://www.w3pop.com/learn/view/doc/dom_obj_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).

Window 对象集合

Collection
集合Description
描述IEFNW3Cframes[]Returns all named frames in the window
返回在window中所有命名过的框架312 

Window object对象

ObjectDescription
描述IEFNW3CclientInformationContains information about the browser
包含有关浏览器的信息4   clipboardData 5   documentThis object can be used to access all elements in a page
这个对象可以用来访问在页面中的所有元素3   eventRepresents the state of an event
某个事件的状态4   external 4   historyContains the URLs the user has visited within a browser window
包含用户在浏览器窗口中所有已经访问过的URL3   locationContains the current URL of the window
包含了当前窗口的URL3   navigatorContains information about the client browser
包含了有关客户端浏览器的信息3   screenContains information about the client's display screen
包含了有关客户端显示屏幕的信息4   

Window 对象属性

Property
属性Description
描述IEFNW3CclosedReturns a Boolean value that specifies whether the referenced window has been closed
获取引用窗口是否已关闭。413 defaultStatusSets or returns the default text in the statusbar of the windows (will be displayed when the page loads)
设置或获取要在窗口底部的状态栏上显示的缺省信息。312 dialogArgumentsReturns all variables passed into the modal dialog window
设置或获取传递给模式对话框窗口的变量或变量数组。4   dialogHeightSets or returns the height of the modal dialog window
设置或获取模式对话框的高度。4   dialogLeftSets or returns the left coordinates of the modal dialog window
设置或获取模式对话框的左坐标。4   dialogTopSets or returns the top coordinates of the modal dialog window
设置或获取模式对话框的顶坐标。4   dialogWidthSets or returns the width of the modal dialog window
设置或获取模式对话框的宽度。4   frameElementReturns the frame/iframe object that is hosting the window in the parent document
获取在父文档中生成 window 的 frame 或 iframe 对象。5   lengthSets or returns the number of frames in the window
设置或获取集合中对象的数目。416 nameSets or returns the name of the window
设置或获取表明窗口名称的值。312 offscreenBufferingSets or returns a Boolean value that specifies whether the window is drawn offscreen before being visible to the user
设置或获取对象在对用户可见之前是否要先在屏幕外绘制。4   openerSets or returns a reference to the window that created the window
设置或获取创建当前窗口的窗口的引用。413 parentReturns the parent window
获取对象层次中的父窗口。312 returnValueSets or returns the value returned from the modal dialog window
设置或获取从模式对话框返回的值。4   screenLeftReturns the x-coordinate of the upper left corner of the browser - relative to the upper left corner of the screen
获取浏览器客户区左上角相对于屏幕左上角的 x 坐标。5   screenTopReturns the y-coordinate of the top corner of the browser - relative to the top corner of the screen
获取浏览器客户区左上角相对于屏幕左上角的 y 坐标。5   selfReturns a reference to the current window
获取对当前窗口或框架的引用。312 statusSets or returns the text in the statusbar of the window
设置或获取位于窗口底部状态栏的信息。312 topReturns the topmost ancestor window
获取最顶层的祖先窗口。312 

Window 对象方法

Method
方法Description
描述IEFNW3Calert()Displays an alert box with a specified message and an OK button
显示包含由应用程序自定义消息的对话框。312 attachEvent("event",pointer)将指定函数绑定到事件,以便每当该事件在对象上触发时都调用该函数。5   blur()Removes focus from the current window
使元素失去焦点并触发 onblur 事件。413 clearInterval(ID)Cancels a timeout that is set with the setInterval() method
取消由setInterval()建立的间隔事件414 clearTimeout(ID)Cancels a timeout that is set with the setTimeout() method
取消由setTimeout()方法建立的间隔事件312 close()Closes the current window
关闭当前浏览器窗口312 confirm()Displays a dialog box with a specified message and an OK and a Cancel button
显示一个确认对话框,其中包含一个可选的消息和确定取消按钮。312 createPopup()Creates a pop-up window
创建弹出窗口。5   execScript("code", "lang")

Executes a specified script. The arguments can take the following values:
以给定语言执行指定的脚本。

codeRequired. The code to be executed
必选。所要执行的代码langRequired. JScript | VBScript | JavaScript
必选。选择代码所属语言类型
4   focus()Sets focus on the current window
聚焦到当前的窗口413 moveBy(x,y)Moves the window a specified number of pixels in relation to its current co-ordinates
将窗口的位置移动指定 xy 偏移值。414 moveTo(x,y)Moves the window's left and top edge to the specified co-ordinates
将窗口左上角的屏幕位置移动到指定的 xy 位置。414 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
打印与窗口关联的文档。514 prompt()

Displays a dialog box that prompts the user for input
显示一个提示对话框,其中带有一条消息和一个输入框。

312 resizeBy()Resizes the window by the specified pixels
更改窗口的当前位置缩放指定的 x 和 y 偏移量。4   resizeTo()Resizes the window to the specified width and height
将窗口的大小更改为指定的宽度和高度值。41.5  scroll()Deprecated. Use scrollTo() instead
将窗口滚动到自左上角起指定的 x 和 y 偏移量。4   scrollBy()Scrolls the content by the specified number of pixels
将窗口滚动 x 和 y 偏移量。414 scrollTo()Scrolls the content to the specified coordinates
将窗口滚动到指定的 x 和 y 偏移量。414 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:
每经过指定毫秒值后计算一个表达式。

codeRequired. A pointer to a function or the code to be executed
必选。指定要执行哪段代码或是函数millisecRequired. The number of milliseconds
必选。毫秒数langOptional. JScript | VBScript | JavaScript
可选。代码语言类型
414 setTimeout()

Calls a function or evaluates an expression after a specified number of milliseconds
经过指定毫秒值后计算一个表达式。

312 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:
显示帮助文件。此方法可用于 Microsoft HTML 帮助。

URLRequired. The URL of a Help file
必选。帮助文件的URLcontextIDOptional. A string or integer that specifies a context identifier in the Help file
可选。指定帮助文件标识方面的字符串或是数
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.
            'URL' - 必选的。所显示文档的URL

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.
参数 - 可选。什么时候显示URL.使用这个参数来传递任何类型的值,可以是数组值。对话框可以从window对象的dialogArguments属性中抽出值

"list" - Optional. Specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:
            'list' - 可选。指定对话框窗口的修饰,用一种或多种下列的值,每个值用分号隔开。

dialogHeight : numberthe height* of the dialog window
对话窗口的高度dialogLeft : numberthe left position of the dialog window
左定位dialogTop : numberthe top position of the dialog window
上定位dialogWidth : numberthe width* of the dialog window
窗口的宽度center : yes | no | 1 | 0 | on | offwhether to center the dialog window within the desktop. Default is yes
是否显示在桌面的中间位置dialogHide : yes | no | 1 | 0 | on | offwhether the dialog window is hidden when printing. Only available when a dialog box is opened from a trusted application. Default is no
是否隐藏所输出的内容,只对于可信的程序所打开的对话框才会有效。默认为 noedge : sunken | raisedthe edge style of the dialog window. Default is raised
对话框窗口的边缘样式help : yes | no | 1 | 0 | on | offwhether the dialog window displays the Help icon. Default is yes
是否显示帮助图标resizable : yes | no | 1 | 0 | on | offwhether the dialog window is resizable. Default is no
对话窗口的大小是否可做调整。默认为否scroll : yes | no | 1 | 0 | on | offwhether the dialog window displays scrollbars. Default is yes
是否显示滚动条,默认为是status : yes | no | 1 | 0 | on | offwhether the dialog window displays a status bar. Default is yes for untrusted dialog windows and no for trusted dialog windows
是否显示底部的状态栏unadorned : yes | no | 1 | 0 | on | offwhether the dialog window displays the border window chrome. Only available when a dialog window is opened from a trusted application. Default is no
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:

dialogHeight : numberthe height* of the dialog windowdialogLeft : numberthe left position of the dialog windowdialogTop : numberthe top position of the dialog windowdialogWidth : numberthe width* of the dialog windowcenter : yes | no | 1 | 0 | on | offwhether to center the dialog window within the desktop. Default is yesdialogHide : yes | no | 1 | 0 | on | offwhether the dialog window is hidden when printing. Only available when a dialog box is opened from a trusted application. Default is noedge : sunken | raisedthe edge style of the dialog window. Default is raisedhelp : yes | no | 1 | 0 | on | offwhether the dialog window displays the Help icon. Default is yesresizable : yes | no | 1 | 0 | on | offwhether the dialog window is resizable. Default is noscroll : yes | no | 1 | 0 | on | offwhether the dialog window displays scrollbars. Default is yesstatus : yes | no | 1 | 0 | on | offwhether the dialog window displays a status bar. Default is yes for untrusted dialog windows and no for trusted dialog windowsunadorned : yes | no | 1 | 0 | on | offwhether the dialog window displays the border window chrome. Only available when a dialog window is opened from a trusted application. Default is no
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 对象事件

语法 window.event_name="someJavaScriptCode"

Event
事件Description
描述IEFNW3ConBlurExecutes some code when a Blur event occurs
对象失去输入焦点时触发。 13 onErrorExecutes some code when an Error event occurs
对象装载过程中发生错误时触发。 13 onFocusExecutes some code when a Focus event occurs
对象获得焦点时触发。 13 onLoadExecutes some code when an Load event occurs
在浏览器完成对象的装载后立即触发。 12 onResizeExecutes some code when a Resize event occurs
对象的大小将要改变时触发。 14 onUnloadExecutes some code when an Unload event occurs
对象卸载前立即触发。 12 
原创粉丝点击