JavaScript allows the creation and opening of windows that represent HTML text, form objects, and frames. The window object is the top-level object in the JavaScript client hierarchy. The form element and all JavaScript code are present in the document, and the document is loaded into the window. To understand You can control how windows work.
Open and close windows
When the user launches Navigator, a window will be automatically created. Users can also use Navigator New Web Browser on the File menu opens a window, and you can use Close or Exit on the Navigator's File menu to close a window. You can also use a program to open or close a window.
Open a window
Create a window using the open method. The following statement creates a window named msgWindow and displays the contents of the file sesame.html in the window.
msgWindow=window.open(" sesame.html")
The following statement can create a window named homeWindow for displaying Netscape's home page.
homeWindow=window.open("http://www .netscape.com")
A window can have two names. The following statement creates a window with two names. The first name is msgWindow, which is used to reference the properties, methods and inclusion relationships of the window. The second name, displayWindow, is used when referencing the window as a form submission or hypertext link object.
When creating a window, it is not required to give a window name. But if you plan to use it from another window To reference this window, this window must have a name. For information about using window names, see the relevant information on windows and frames.
When opening a window, you can specify the window properties, such as the height and width of the window, and whether it contains tools. bar, location field or scroll bar, etc. The following statement creates a window without toolbar but with scroll bar.
msgWindow=window.open
("sesame.html","displayWindow ","toolbar=no,scrollbars=yes")
For details about the properties of the window, please see the OPEN method.
Close the window
You can use the method close in the program to close a Window. It is not allowed to close only one frame without closing the entire parent window.
The following statements can close the current window:
window.close()
self.close( )
//This statement cannot be used in event handlers
close()
The following statement closes a window named msgWindow:
msgWindow.close()
----------------------------------------- ---------------------------------------------
Use frame
frame是一种特殊的窗口,它可以在一个窗口显示多个独立滚动的frame.每个frame又有各自不同的URL. 各frame可以指向不同的URL,也可以作为其它URL目标,但必须在同一个窗口内. 一系列的frame 组成页(page).
下图是一个含有三个frame的窗口
This frame is This frame is
named listFrame named contentFrame
| |
-----------------v-----------------------------------v------------
| Music Club | Toshiko Akiyoshi |
| Artists | Interlude |
| Jazz | The Beatles |
| - T. Akiyoshi | Please Please Me |
| _ J. Coltrame | |
| - M. Davis | Betty carter |
| - D. Gordon | Ray Charles and Betty Carter |
| Soul | Jimmy Cliff |
| - B. Carter | The Harder They Come |
| _ R. Charles | |
| ... | ... |
------------------------------------------------------------------
| Alphabetical By category Musician Descriptions |
-----------------^------------------------------------------------
|
This frame is named
navigateFrame
创建一个frame
在HTML文档中使用
Jazz
Soul
Interlude
The Beatles
Please Please Me
Betty Carter
Ray Charles and Betty Carter
...
For details on the syntax of creating a frame, see the frame object.
------------- -------------------------------------------------- ----------------
Reference window and frame
Which name you use to reference the window depends on whether you want to reference the properties of the window. , methods and event handlers, you still want to use window as an object for form submission or hypertext link.
Because the window object is located at the top level of the JavaScript client hierarchy. Window is a description of the included relationship between objects in the window. Basics.
Reference the properties, methods and event handlers of the window
You can use one of the following methods to reference the properties, methods and event handlers of the current window or other windows:
self Or window: self and window have the same meaning, they both refer to the current window. You can choose either one to refer to the current window. For example, call window.close() or self.close() to close the current window
top or parent: Both top and parent are used to replace the name of the window. top refers to the top Navigator window, and parent refers to the window containing the frameset. For example, the statement parent.frame2.document.bgColor="teal" changes the name of the frame named frame2 Set the background color to teal. frame2 is a frame of the current frameset.
The name of the window variable: The window variable name is the variable specified when the window is opened. For example, msgWindow.close closes the window named msgWindow. But if you want to use the event To open or close a window in the handler, you must use window.open() or window.close(), but not open() and close(). Due to the scope problem of static objects in JavaScript, close is called without specifying The object name is equivalent to document.close().
Omit the window name. Because the current window is always assumed, the window name can be omitted when calling the window's methods and using its properties. For example, close() closes the current window.
For information about window methods, see the window object
Example 1 References the current window. The following statement references a form named musicform in the current window. If the check box is checked, this statement displays an alert .
if (self.document.musicForm.checkbox1.checked)
alert('The checkbox on the misicForm is checked')
Example 2 refers to other windows. The following statement quotes A form named musicform located in the window checkboxWin is created. These statements determine whether the check box is checked, execute the check box, determine whether an option of the select object is selected, and select an option of the SELECT object
/ /Determine whether the checkbox is checked
if (checkboxWin.document.musicForm.checkbox2.checked) {
alert('The checkbox on the misicForm in checkboxWin is checked')}
//Execute checking of the checkbox
checkboxWin.document.musicForm.checkbox2.checked=true
//Determine whether an option of the select object is selected
if (checkboxWin .document.musicForm.musicTypes.options[1].selected)
alert('Option 1 is selected!')
//Select an option of the SELECT object
checkboxWin.document.musicForm. musicTypes.selectedIndex=1
Example 3 refers to a frame in another window. The following statement refers to a frame named frame2 in window window2. This statement changes the background color of frame2 to purple, and the name frame2 Must be specified in the