|
【目录】 【上一页】 【下一页】 【索引】
WindowRepresents a browser window or frame. This is the top-level object for each document, Location, and History object group.
创建源The JavaScript runtime engine creates a Window object for each BODY or FRAMESET tag. It also creates a Window object to represent each frame defined in a FRAME tag. In addition, you can create other windows by calling the Window.open method. For details on defining a window, see open.事件句柄In Navigator 3.0, on some platforms, placing an onBlur or onFocus event handler in a FRAMESET tag has no effect.描述The Window object is the top-level object in the JavaScript client hierarchy. A Window object can represent either a top-level window or a frame inside a frameset. As a matter of convenience, you can think about a Frame object as a Window object that isn't a top-level window. However, there is not really a separate Frame class; these objects really are Window objects, with a very few minor differences:
Because the existence of the current window is assumed, you do not have to refer to the name of the window when you call its methods and assign its properties. For example, status="Jump to a new location" is a valid property assignment, and close() is a valid method call. However, when you open or close a window within an event handler, you must specify window.open() or window.close() instead of simply using open() or close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close(). For the same reason, when you refer to the location object within an event handler, you must specify window.location instead of simply using location. A call to location without specifying an object name is equivalent to document.location, which is a synonym for document.URL. You can refer to a window's Frame objects in your code by using the frames array. In a window with a FRAMESET tag, the frames array contains an entry for each frame. A windows lacks event handlers until HTML that contains a BODY or FRAMESET tag is loaded into it. 属性概览
方法概览
示例示例 1. Windows opening other windows. In the following example, the document in the top window opens a second window, window2, and defines push buttons that open a message window, write to the message window, close the message window, and close window2. The onLoad and onUnload event handlers of the document loaded into window2 display alerts when the window opens and closes.win1.html, which defines the frames for the first window, contains the following code:
<HTML>
<HTML>
<HTML>
<HTML>
<HTML>
<HTML>
<HTML> 参看document, Frame属性closedSpecifies whether a window is closed.
描述The closed property is a boolean value that specifies whether a window has been closed. When a window closes, the window object that represents it continues to exist, and its closed property is set to true.Use closed to determine whether a window that you opened, and to which you still hold a reference (from the return value of window.open), is still open. Once a window is closed, you should not attempt to manipulate it. 示例示例 1. The following code opens a window, win1, then later checks to see if that window has been closed. A function is called depending on whether win1 is closed.
win1=window.open('opener1.html','window1','width=300,height=300')
if (window.opener.closed) 参看Window.close, Window.opendefaultStatusThe default message displayed in the status bar at the bottom of the window.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。描述The defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor.You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOut or onMouseOver event handlers. 示例In the following example, the statusSetter function sets both the status and defaultStatus properties in an onMouseOver event handler:
function statusSetter() { 参看Window.statusdocumentContains information on the current document, and provides methods for displaying HTML output to the user.
描述The value of this property is the window's associated document object.framesAn array of objects corresponding to child frames (created with the FRAME tag) in source order.
You can refer to the child frames of a window by using the frames array. This array contains an entry for each child frame (created with the FRAME tag) in a window containing a FRAMESET tag; the entries are in source order. For example, if a window contains three child frames whose NAME attributes are fr1, fr2, and fr3, you can refer to the objects in the images array either as:
parent.frames["fr1"]
parent.frames[0] The value of each element in the frames array is <object nameAttribute>, where nameAttribute is the NAME attribute of the frame. historyContains information on the URLs that the client has visited within a window.
描述The value of this property is the window's associated History object.innerHeightSpecifies the vertical dimension, in pixels, of the window's content area.
描述To create a window smaller than 100 x 100 pixels, set this property in a signed script.安全性To set the inner height of a window to a size smaller than 100 x 100 or larger than the screen can accommodate, you need the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。参看Window.innerWidth, Window.outerHeight, Window.outerWidthinnerWidthSpecifies the horizontal dimension, in pixels, of the window's content area.
描述To create a window smaller than 100 x 100 pixels, set this property in a signed script.安全性To set the inner width of a window to a size smaller than 100 x 100 or larger than the screen can accommodate, you need the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。参看Window.innerHeight, Window.outerHeight, Window.outerWidthlengthThe number of child frames in the window.
描述This property gives you the same result as using the length property of the frames array.locationContains information on the current URL.
描述The value of this property is the window's associated Location object.locationbarRepresents the browser window's location bar (the region containing the bookmark and URL areas).
描述The value of the locationbar property itself has one property, visible. If true, the location bar is visible; if false, it is hidden.安全性Setting the value of the location bar's visible property requires the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例The following example would make the referenced window "chromeless" (chromeless windows lack toolbars, scrollbars, status areas, and so on, much like a dialog box) by hiding most of the user interface toolbars:
self.menubar.visible=false; menubarRepresents the browser window's menu bar. This region contains browser's drop-down menus such as File, Edit, View, Go, Communicator, and so on.
描述The value of the menubar property itself one property, visible. If true, the menu bar is visible; if false, it is hidden.安全性Setting the value of the menu bar's visible property requires the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例The following example would make the referenced window "chromeless" (chromeless windows lack toolbars, scrollbars, status areas, and so on, much like a dialog box) by hiding most of the user interface toolbars:
self.menubar.visible=false; nameA string specifying the window's name.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。描述In Navigator 2.0, NAME was a read-only property. In later versions, this property is modifiable by your code. This allows you to assign a name to a top-level window.示例In the following example, the first statement creates a window called netscapeWin. The second statement displays the value "netscapeHomePage" in the Alert dialog box, because "netscapeHomePage" is the value of the windowName argument of netscapeWin.
netscapeWin=window.open("http://home.netscape.com","netscapeHomePage") openerSpecifies the window of the calling document when a window is opened using the open method.
描述When a source document opens a destination window by calling the open method, the opener property specifies the window of the source document. Evaluate the opener property from the destination window.This property persists across document unload in the opened window. You can change the opener property at any time. You may use Window.open to open a new window and then use Window.open on that window to open another window, and so on. In this way, you can end up with a chain of opened windows, each of which has an opener property pointing to the window that opened it. Communicator allows a maximum of 100 windows to be around at once. If you open window2 from window1 and then are done with window1, be sure to set the opener property of window2 to null. This allows JavaScript to garbage collect window1. If you do not set the opener property to null, the window1 object remains, even though it's no longer really needed. 示例示例 1: Close the opener. The following code closes the window that opened the current window. When the opener window closes, opener is unchanged. However, window.opener.name then evaluates to undefined.window.opener.close() 示例 2: Close the main browser window. top.opener.close() 示例 3: Evaluate the name of the opener. A window can determine the name of its opener as follows: document.write("<BR>opener property is " + window.opener.name) 示例 4: Change the value of opener. The following code changes the value of the opener property to null. After this code executes, you cannot close the opener window as shown in Example 1. window.opener=null 示例 5: Change a property of the opener. The following code changes the background color of the window specified by the opener property. window.opener.document.bgColor='bisque' 参看Window.close, Window.openouterHeightSpecifies the vertical dimension, in pixels, of the window's outside boundary.
描述The outer boundary includes the scroll bars, the status bar, the tool bars, and other "chrome" (window border user interface elements). To create a window smaller than 100 x 100 pixels, set this property in a signed script.参看Window.innerWidth, Window.innerHeight, Window.outerWidthouterWidthSpecifies the horizontal dimension, in pixels, of the window's outside boundary.
描述The outer boundary includes the scroll bars, the status bar, the tool bars, and other "chrome" (window border user interface elements). To create a window smaller than 100 x 100 pixels, set this property in a signed script.参看Window.innerWidth, Window.innerHeight, Window.outerHeightpageXOffsetProvides the current x-position, in pixels, of a window's viewed page.
描述The pageXOffset property provides the current x-position of a page as it relates to the upper-left corner of the window's content area. This property is useful when you need to find the current location of the scrolled page before using scrollTo or scrollBy.示例The following example returns the x-position of the viewed page.参看Window.pageYOffsetpageYOffsetProvides the current y-position, in pixels, of a window's viewed page.
描述The pageYOffset property provides the current y-position of a page as it relates to the upper-left corner of the window's content area. This property is useful when you need to find the current location of the scrolled page before using scrollTo or scrollBy.示例The following example returns the y-position of the viewed page.参看Window.pageXOffsetparentThe parent property is the window or frame whose frameset contains the current frame.
描述This property is only meaningful for frames; that is, windows that are not top-level windows.The parent property refers to the FRAMESET window of a frame. Child frames within a frameset refer to sibling frames by using parent in place of the window name in one of the following ways:
parent.frameName You can use parent.parent to refer to the "grandparent" frame or window when a FRAMESET tag is nested within a child frame. The value of the parent property is <object nameAttribute> where nameAttribute is the NAME attribute if the parent is a frame, or an internal reference if the parent is a window. 示例See示例 for Frame.personalbarRepresents the browser window's personal bar (also called the directories bar). This is the region the user can use for easy access to certain bookmarks.
描述The value of the personalbar property itself one property, visible. If true, the personal bar is visible; if false, it is hidden.安全性Setting the value of the personal bar's visible property requires the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例The following example would make the referenced window "chromeless" (chromeless windows lack toolbars, scrollbars, status areas, and so on, much like a dialog box) by hiding most of the user interface toolbars:
self.menubar.visible=false; scrollbarsRepresents the browser window's vertical and horizontal scroll bars for the document area.
描述The value of the scrollbars property itself has one property, visible. If true, both scrollbars are visible; if false, they are hidden.安全性Setting the value of the scrollbars' visible property requires the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例The following example would make the referenced window "chromeless" (chromeless windows lack toolbars, scrollbars, status areas, and so on, much like a dialog box) by hiding most of the user interface toolbars:
self.menubar.visible=false; selfThe self property is a synonym for the current window.
描述The self property refers to the current window. That is, the value of this property is a synonym for the object itself.Use the self property to disambiguate a window property from a form or form element of the same name. You can also use the self property to make your code more readable. The value of the self property is <object nameAttribute> where nameAttribute is the NAME attribute if self refers to a frame, or an internal reference if self refers to a window. 示例In the following example, self.status is used to set the status property of the current window. This usage disambiguates the status property of the current window from a form or form element called status within the current window.
<A HREF="" statusSpecifies a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor.
安全性Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”。描述Do not confuse the status property with the defaultStatus property. The defaultStatus property reflects the default message displayed in the status bar.You can set the status property at any time. You must return true if you want to set the status property in the onMouseOver event handler. 示例Suppose you have created a JavaScript function called pickRandomURL that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property:
<A HREF="" 参看Window.defaultStatusstatusbarRepresents the browser window's status bar. This is the region containing the security indicator, browser status, and so on.
描述The value of the statusbar property itself one property, visible. If true, the status bar is visible; if false, it is hidden.安全性Setting the value of the status bar's visible property requires the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例The following example would make the referenced window "chromeless" (chromeless windows lack toolbars, scrollbars, status areas, and so on, much like a dialog box) by hiding most of the user interface toolbars:
self.menubar.visible=false; toolbarRepresents the browser window's tool bar, containing the navigation buttons, such as Back, Forward, Reload, Home, and so on.
描述The value of the toolbar property itself one property, visible. If true, the tool bar is visible; if false, it is hidden.安全性Setting the value of the tool bar's visible property requires the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例The following example would make the referenced window "chromeless" (chromeless windows lack toolbars, scrollbars, status areas, and so on, much like a dialog box) by hiding most of the user interface toolbars:
self.menubar.visible=false; topThe top property is a synonym for the topmost browser window, which is a document window or web browser window.
描述The top property refers to the topmost window that contains frames or nested framesets. Use the top property to refer to this ancestor window.The value of the top property is <object objectReference> where objectReference is an internal reference. 示例The statement top.close() closes the topmost ancestor window.The statement top.length specifies the number of frames contained within the topmost ancestor window. When the topmost ancestor is defined as follows, top.length returns three:
<FRAMESET COLS="30%,40%,30%"> top.myFrame.document.bgColor="red" windowThe window property is a synonym for the current window or frame.
描述The window property refers to the current window or frame. That is, the value of this property is a synonym for the object itself.Although you can use the window property as a synonym for the current frame, your code may be more readable if you use the self property. For example, window.name and self.name both specify the name of the current frame, but self.name may be easier to understand (because a frame is not displayed as a separate window). Use the window property to disambiguate a property of the window object from a form or form element of the same name. You can also use the window property to make your code more readable. The value of the window property is <object nameAttribute> where nameAttribute is the NAME attribute if window refers to a frame, or an internal reference if window refers to a window. 示例In the following example, window.status is used to set the status property of the current window. This usage disambiguates the status property of the current window from a form called "status" within the current window.
<A HREF="" 参看Window.self方法alertDisplays an Alert dialog box with a message and an OK button.
语法alert("message")参数
描述An alert dialog box looks as follows:
Use the alert method to display a message that does not require a user decision. The message argument specifies a message that the dialog box contains. You cannot specify a title for an alert dialog box, but you can use the open method to create your own alert dialog box. See open. 示例In the following example, the testValue function checks the name entered by a user in the Text object of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user to enter a valid value.
function testValue(textElement) {
Name: <INPUT TYPE="text" NAME="userName" 参看Window.confirm, Window.promptbackUndoes the last history step in any frame within the top-level window; equivalent to the user pressing the browser's Back button.
语法back()参数无描述Calling the back method is equivalent to the user pressing the browser's Back button. That is, back undoes the last step anywhere within the top-level window, whether it occurred in the same frame or in another frame in the tree of frames loaded from the top-level window. In contrast, the history object's back method backs up the current window or frame history one step.For example, consider the following scenario. While in Frame A, you click the Forward button to change Frame A's content. You then move to Frame B and click the Forward button to change Frame B's content. If you move back to Frame A and call FrameA.back(), the content of Frame B changes (clicking the Back button behaves the same). If you want to navigate Frame A separately, use FrameA.history.back(). 示例The following custom buttons perform the same operation as the browser's Back button:
<P><INPUT TYPE="button" VALUE="< Go Back" 参看Window.forward, History.backblurRemoves focus from the specified object.
语法blur()参数无描述Use the blur method to remove focus from a specific window or frame. Removing focus from a window sends the window to the background in most windowing systems.参看Window.focuscaptureEventsSets the window to capture all events of the specified type.
语法captureEvents(eventType)参数
安全性When a window with frames wants to capture events in pages loaded from different locations (servers), you need to use captureEvents in a signed script and precede it with enableExternalCapture. You must have the UniversalBrowserWrite privilege. For more information and an example, see enableExternalCapture. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。参看captureEvents works in tandem with releaseEvents, routeEvent, and handleEvent. For more information, see "Events in Navigator 4.0".clearIntervalCancels a timeout that was set with the setInterval method.
语法clearInterval(intervalID)参数
描述See setInterval.示例See setInterval.参看Window.setIntervalclearTimeoutCancels a timeout that was set with the setTimeout method.
语法clearTimeout(timeoutID)参数
描述See setTimeout.示例See setTimeout.参看Window.clearInterval, Window.setTimeoutcloseCloses the specified window.
语法close()参数无安全性Navigator 4.0: To unconditionally close a window, you need the UniversalBrowserWrite privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。描述The close method closes the specified window. If you call close without specifying a windowReference, JavaScript closes the current window.The close method closes only windows opened by JavaScript using the open method. If you attempt to close any other window, a confirm is generated, which lets the user choose whether the window closes. This is a security feature to prevent "mail bombs" containing self.close(). However, if the window has only one document (the current one) in its session history, the close is allowed without any confirm. This is a special case for one-off windows that need to open other windows and then dispose of themselves. In event handlers, you must specify window.close() instead of simply using close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close(). 示例示例 1. Any of the following示例 closes the current window:
window.close() top.opener.close() 示例 3. The following example closes the messageWin window: messageWin.close() This example assumes that the window was opened in a manner similar to the following: 参看Window.closed, Window.openconfirmDisplays a Confirm dialog box with the specified message and OK and Cancel buttons.
语法confirm("message")参数
描述A confirm dialog box looks as follows:
Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The message argument specifies a message that prompts the user for the decision. The confirm method returns true if the user chooses OK and false if the user chooses Cancel. You cannot specify a title for a confirm dialog box, but you can use the open method to create your own confirm dialog. See open. 示例This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp function closes the application.
function confirmCleanUp() { <INPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()"> 参看Window.alert, Window.promptdisableExternalCaptureDisables external event capturing set by the enableExternalCapture method.
语法disableExternalCapture()参数无描述See enableExternalCapture.enableExternalCaptureAllows a window with frames to capture events in pages loaded from different locations (servers).
语法enableExternalCapture()参数无描述Use this method in a signed script requesting UniversalBrowserWrite privileges, and use it before calling the captureEvents method.If Communicator sees additional scripts that cause the set of principals in effect for the container to be downgraded, it disables external capture of events. Additional calls to enableExternalCapture (after acquiring the UniversalBrowserWrite privilege under the reduced set of principals) can be made to enable external capture again. 示例In the following example, the window is able to capture all Click events that occur across its frames.
<SCRIPT ARCHIVE="myArchive.jar" ID="2"> 参看Window.disableExternalCapture, Window.captureEventsfindFinds the specified text string in the contents of the specified window.
语法find(string, casesensitive, backward)参数
返回true if the string is found; otherwise, false.描述When a string is specified, the browser performs a case-insensitive, forward search. If a string is not specified, the method displays the Find dialog box, allowing the user to enter a search string.focusGives focus to the specified object.
语法focus()参数无描述Use the focus method to navigate to a specific window or frame, and give it focus. Giving focus to a window brings the window forward in most windowing systems.In Navigator 3.0, on some platforms, the focus method gives focus to a frame but the focus is not visually apparent (for example, the frame's border is not darkened). 示例In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the Password object and the select method highlights it so the user can reenter the password.
function checkPassword(userPass) { <INPUT TYPE="password" NAME="userPass"> 参看Window.blurforwardPoints the browser to the next URL in the current history list; equivalent to the user pressing the browser's Forward button
语法history.forward() forward()参数无描述This method performs the same action as a user choosing the Forward button in the browser. The forward method is the same as history.go(1).When used with the Frame object, forward behaves as follows: While in Frame A, you click the Back button to change Frame A's content. You then move to Frame B and click the Back button to change Frame B's content. If you move back to Frame A and call FrameA.forward(), the content of Frame B changes (clicking the Forward button behaves the same). If you want to navigate Frame A separately, use FrameA.history.forward(). 示例The following custom buttons perform the same operation as the browser's Forward button:
<P><INPUT TYPE="button" VALUE="< Go Forth" 参看Window.backhandleEvent调用指定事件的控制句柄。
语法handleEvent(event)参数
描述handleEvent works in tandem with captureEvents, releaseEvents, and routeEvent. For more information, see "Events in Navigator 4.0".homePoints the browser to the URL specified in preferences as the user's home page; equivalent to the user pressing the browser's Home button.
语法home()参数无描述This method performs the same action as a user choosing the Home button in the browser.moveByMoves the window relative to its current position, moving the specified number of pixels.
语法moveBy(horizontal, vertical)参数
描述This method moves the window by adding or subtracting the specified number of pixels to the current location.安全性Exceeding any of the boundaries of the screen (to hide some or all of a window) requires signed JavaScript, so a window won't move past the screen boundaries. You need the UniversalBrowserWrite privilege for this. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例:To move the current window 5 pixels up towards the top of the screen (x-axis), and 10 pixels towards the right (y-axis) of the current window position, use this statement:self.moveBy(-5,10); // relative positioning 参看Window.moveTomoveToMoves the top-left corner of the window to the specified screen coordinates.
语法moveTo(x-coordinate, y-coordinate)参数
描述This method moves the window to the absolute pixel location indicated by its parameters. The origin of the axes is at absolute position (0,0); this is the upper left-hand corner of the display.安全性Exceeding any of the boundaries of the screen (to hide some or all of a window) requires signed JavaScript, so a window won't move past the screen boundaries. You need the UniversalBrowserWrite privilege for this. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例:To move the current window to 25 pixels from the top boundary of the screen (x-axis), and 10 pixels from the left boundary of the screen (y-axis), use this statement:self.moveTo(25,10); // absolute positioning 参看Window.moveByopenOpens a new web browser window.
语法open(URL, windowName, windowFeatures)参数
描述In event handlers, you must specify window.open() instead of simply using open(). Due to the scoping of static objects in JavaScript, a call to open() without specifying an object name is equivalent to document.open().The open method opens a new Web browser window on the client, similar to choosing New Navigator Window from the File menu of the browser. The URL argument specifies the URL contained by the new window. If URL is an empty string, a new, empty window is created. You can use open on an existing window, and if you pass the empty string for the URL, you will get a reference to the existing window, but not load anything into it. You can, for example, then look for properties in the window. windowFeatures is an optional string containing a comma-separated list of options for the new window (do not include any spaces in this list). After a window is open, you cannot use JavaScript to change the windowFeatures. The features you can specify are:
Many of these features (as noted above) can either be yes or no. For these features, you can use 1 instead of yes and 0 instead of no. If you want to turn a feature on, you can also simply list the feature name in the windowFeatures string. If windowName does not specify an existing window and you do not supply the windowFeatures parameter, all of the features which have a yes/no choice are yes by default. However, if you do supply the windowFeatures parameter, then the titlebar and hotkeys are still yes by default, but the other features which have a yes/no choice are no by default. For example, all of the following statements turn on the toolbar option and turn off all other Boolean options:
open("", "messageWindow", "toolbar") open("", "messageWindow", "toolbar,directories=yes") How the alwaysLowered, alwaysRaised, and z-lock features behave depends on the windowing hierarchy of the platform. For example, on Windows, an alwaysLowered or z-locked browser window is below all windows in all open applications. On Macintosh, an alwaysLowered browser window is below all browser windows, but not necessarily below windows in other open applications. Similarly for an alwaysRaised window. You may use open to open a new window and then use open on that window to open another window, and so on. In this way, you can end up with a chain of opened windows, each of which has an opener property pointing to the window that opened it. Communicator allows a maximum of 100 windows to be around at once. If you open window2 from window1 and then are done with window1, be sure to set the opener property of window2 to null. This allows JavaScript to garbage collect window1. If you do not set the opener property to null, the window1 object remains, even though it's no longer really needed. 安全性To perform the following operations using the specified screen features, you need the UniversalBrowserWrite privilege:
示例示例 1. In the following example, the windowOpener function opens a window and uses write methods to display a message:
function windowOpener() {
<FORM NAME="myform"> 参看Window.close
语法print()参数无promptDisplays a Prompt dialog box with a message and an input field.
语法prompt(message, inputDefault)参数
描述A prompt dialog box looks as follows:
Use the prompt method to display a dialog box that receives user input. If you do not specify an initial value for inputDefault, the dialog box displays <undefined>. You cannot specify a title for a prompt dialog box, but you can use the open method to create your own prompt dialog. See open. 示例prompt("Enter the number of cookies you want to order:", 12)参看Window.alert, Window.confirmreleaseEventsSets the window or document to release captured events of the specified type, sending the event to objects further along the event hierarchy.
NoteIf the original target of the event is a window, the window receives the event even if it is set to release that type of event.语法releaseEvents(eventType)参数
描述releaseEvents works in tandem with captureEvents, routeEvent, and handleEvent. For more information, see "Events in Navigator 4.0".resizeByResizes an entire window by moving the window's bottom-right corner by the specified amount.
语法resizeBy(horizontal, vertical)参数
描述This method changes the window's dimensions by setting its outerWidth and outerHeight properties. The upper left-hand corner remains anchored and the lower right-hand corner moves. resizeBy moves the window by adding or subtracting the specified number of pixels to that corner's current location.安全性Exceeding any of the boundaries of the screen (to hide some or all of a window) requires signed JavaScript, so a window won't move past the screen boundaries. In addition, windows have an enforced minimum size of 100 x 100 pixels; resizing a window to be smaller than this minimum requires signed JavaScript. You need the UniversalBrowserWrite privilege for this. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例To make the current window 5 pixels narrower and 10 pixels taller than its current dimensions, use this statement:self.resizeBy(-5,10); // relative positioning 参看Window.resizeToresizeToResizes an entire window to the specified pixel dimensions.
语法resizeTo(outerWidth, outerHeight)参数
描述This method changes the window's dimensions by setting its outerWidth and outerHeight properties. The upper left-hand corner remains anchored and the lower right-hand corner moves. resizeBy moves to the specified position. The origin of the axes is at absolute position (0,0); this is the upper left-hand corner of the display.安全性Exceeding any of the boundaries of the screen (to hide some or all of a window) requires signed JavaScript, so a window won't move past the screen boundaries. In addition, windows have an enforced minimum size of 100 x 100 pixels; resizing a window to be smaller than this minimum requires signed JavaScript. You need the UniversalBrowserWrite privilege for this. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。示例To make the window 225 pixels wide and 200 pixels tall, use this statement:self.resizeTo(225,200); // absolute positioning 参看Window.resizeByrouteEventPasses a captured event along the normal event hierarchy.
语法routeEvent(event)参数
描述If a subobject (document or layer) is also capturing the event, the event is sent to that object. Otherwise, it is sent to its original target.routeEvent works in tandem with captureEvents, releaseEvents, and handleEvent. For more information, see "Events in Navigator 4.0". scrollScrolls a window to a specified coordinate.
描述In Navigator 4.0, scroll is no longer used and has been replaced by scrollTo. scrollTo extends the capabilities of scroll. scroll remains for backward compatibility.scrollByScrolls the viewing area of a window by the specified amount.
语法scrollBy(horizontal, vertical)参数
描述This method scrolls the content in the window if portions that can't be seen exist outside of the window. scrollBy scrolls the window by adding or subtracting the specified number of pixels to the current scrolled location.For this method to have an effect the visible property of Window.scrollbars must be true. 示例To scroll the current window 5 pixels towards the left and 30 pixels down from the current position, use this statement:self.scrollBy(-5,30); // relative positioning 参看Window.scrollToscrollToScrolls the viewing area of the window so that the specified point becomes the top-left corner.
语法scrollTo(x-coordinate, y-coordinate)参数
描述scrollTo replaces scroll. scroll remains for backward compatibility.The scrollTo method scrolls the content in the window if portions that can't be seen exist outside of the window. For this method to have an effect the visible property of Window.scrollbars must be true. 示例示例 1: Scroll the current viewing area. To scroll the current window to the leftmost boundary and 20 pixels down from the top of the window, use this statement:self.scrollTo(0,20); // absolute positioning 示例 2: Scroll a different viewing area. The following code, which exists in one frame, scrolls the viewing area of a second frame. Two Text objects let the user specify the x and y coordinates. When the user clicks the Go button, the document in frame2 scrolls to the specified coordinates.
<SCRIPT> 参看Window.scrollBysetIntervalEvaluates an expression or calls a function every time a specified number of milliseconds elapses, until canceled by a call to clearInterval.
语法setInterval(expression, msec)setInterval(function, msec, arg1, ..., argN) 参数
描述The timeouts continue to fire until the associated window or frame is destroyed or the interval is canceled using the clearInterval method.参看Window.clearInterval, Window.setTimeoutsetTimeoutEvaluates an expression or calls a function once after a specified number of milliseconds elapses.
语法setTimeout(expression, msec)setTimeout(function, msec, arg1, ..., argN) 参数
描述The setTimeout method evaluates an expression or calls a function after a specified amount of time. It does not act repeatedly. For example, if a setTimeout method specifies five seconds, the expression is evaluated or the function is called after five seconds, not every five seconds. For repetitive timeouts, use the setInterval method.setTimeout does not stall the script. The script continues immediately (not waiting for the timeout to expire). The call simply schedules an additional future event. 示例示例 1. The following example displays an alert message five seconds (5,000 milliseconds) after the user clicks a button. If the user clicks the second button before the alert message is displayed, the timeout is canceled and the alert does not display.
<SCRIPT LANGUAGE="JavaScript">
<HEAD> 参看Window.clearTimeout, Window.setIntervalstopStops the current download.
语法stop()参数无DefinitionThis method performs the same action as a user choosing the Stop button in the browser.
【目录】 【上一页】 【下一页】 【索引】 |