Javascript tips for learning Essays (using Windows and frames) _ javascript skills

Source: Internet
Author: User
Javascript (using Windows and frames) Tips JavaScript allows you to create and open windows that represent HTML text, form objects, and frames. the window object is the top-level object of the JavaScript client hierarchy. The form element and all JavaScript code exist in the document, and the document is loaded into the window. to understand how Windows work, you can control these windows.

Open and Close windows
When the user starts the (launch) Navigator, a window is automatically created. you can also use the New Web Browser on the File menu of Navigator to open a window. You can Close a window using the Close or Exit of the File menu of Navigator. you can also use a program to open or close a window.

Open Window
Create a window named msgwindowand display the content of the file sesame.html in the window.

MsgWindow = window. open ("sesame.html ")

The following statement creates a window named homeWindow to display the home page of Netscape.

HomeWindow = window. open ("http://www.netscape.com ")

The window can have two names. the following statement creates a window with two names. The first one is msgWindow, which is used to reference the properties, methods, and inclusion relationships of the window, the second name displayWindow is used to reference a window as an object submitted by form or hypertext chain.

When creating a window, the window name is not required. however, if you want to reference this window from another window, this window must have a name. for more information about window names, see windows and frames.

When opening a window, you can specify window properties, such as the window height, width, tool bar, location field, or scroll bar. The following statement creates a window with no toolbar but a scroll bar.

MsgWindow = window. open
("Sesame.html", "displayWindow", "toolbar = no, scrollbars = yes ")

For details about window properties, see OPEN method.

Close Window
You can close a window by using the close method in the program. You cannot close only one frame but not the entire parent window.

The following statement 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
A frame is a special window that displays multiple independent scrolling frames in one window. each frame has a different URL. each frame can point to a different URL or be used as another URL destination, but it must be in the same window. A series of frames form pages ).

Is a window containing three frames

This frame is
Named listFrame named contentFrame

|
----------------- V --------------------------------- v ------------
| Music Club | Toshiko Akiyoshi |
| Artists | Interlude |

| Jazz | The Beatles |
|-T. Akiyoshi | 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
Create a frame
Use in HTML documentsYou can create a frame.The unique role of tag in HTML documents is to define the layout of each frame of a page ).

Example 1 the language name defines a set of frames as shown in


 
   
ALT = "BACKWARD" HEIGHT = 32 WIDTH = 32>  
 


Given the hierarchy of these frames, although two frames are defined in another frameset, the three frames have the same parent, this is because the father of frame is its parent window, and the window is determined by frame rather than frameset.

Top

+ -- ListFrame (category.html)

Certificate --contentframe(titles.html)

+--NavigateFrame(navigate.html)
You can also reference the above frame in the array frames (for information about the array frames, see the frame object ):
Listframe is represented by top. frame [0 ].
Contentframe is represented by top. frame [1 ].
Navigateframe is represented by top. frame [2 ].
For example 2, you can use another method to create the above window: The first two frames and navigateFrame have different parent nodes. The top-layer frameset is defined as follows:


  
ALT = "BACKWARD" HEIGHT = 32 WIDTH = 32>

The file muskel3.html contains the frame skeleton and defines the following frameset.


  
ALT = "BACKWARD" HEIGHT = 32 WIDTH = 32>

It shows the hierarchies of these frames. upperFrame and navigateFrame share a parent: the top window. While listFrame and contentFrame share a parent: upperFrame.

Top

| + -- ListFrame
| (Category.html)
+ --- UpperFrame ----------- |
| (Muske13.html) |
| + -- ContentFrame
| (Titles.html)

+ -- NavigateFrame
(Navigate.html)
You can use the following method to reference these frames (for details about the frame array, refer to the frame object ).
UpperFrame is represented by top. frame [0 ].
NavigateFrame is represented by top. frame [1 ].
ListFrame is represented by upperFrame. frames [0] or top. frames [0]. frames [0 ].
ContentFrame is represented by upperFrame. frames [1] or top. frames [0]. frames [1 ].
Update frame (updating frames)
As long as you describe the frame hierarchy, you can use the location attribute to set the URL to update the frame content.

For example, if you want to disable a frame (named listframe) containing a list of painters in alphabetical or sorted order when using frameset in example 2 above ), you can add the following buttons to navigateFrame if you only want to see the title of a work sorted by the composer (in contentFrame.

OnClick = "top.frames%0%.location%'artists.html '">

When the user presses this button, the file artist.html is loaded into the frame named upperFrame, And the listFrame and contentFrame are closed and no longer exist.

Reference frame and browse between frames (navigate)
Because frame is a window, you can reference frame and browse between frames in a similar way.

Frame example
In the previous section, if frameset is designed as a title available for a music club, these frames and their HTML files include the following:

Category.html is located in listFrame and contains a list of composite sorted by category.
Titles.html is located in contentFrame and contains the name of each composer in a letter sequence and the title of the composer.
Navigate.html is located in navigateFrame and has a hypertext chain. This allows you to select how to display the composite in the listFrame: In alphabetical or categorical order. this file also defines a hypertext chain that allows you to display the introduction of each composer.
The additional file alphabet.html contains a letter-ordered composite. When you want to display a letter sequence table, click the chain and the file is displayed in listFrame.
Code contained in file category.html (sorted by category) is similar to the following:

Music Club Artists

Jazz

  • Toshiko Akiyoshi
  • Jon Coltrane
  • Miles Davis
  • Dexter Gordon

    Soul

  • Betty Cater
  • Ray Charles
    ...

    The Code contained in the file alphabet.html (in alphabetical order) is similar to the following:

    Music Club Artists
  • Toshiko Akiyoshi
  • The Beatles
  • Betty Carter
  • Ray Charles
    ......

    The Code contained in the navigate.html file (the navigation chain at the bottom of the screen) is similar to the following. note: The target of artists.html is "_ parent ". when you press this link, the entire window is overwritten because the top window is the parent of navigateFrame.

    Alphabetical

    By category


    Musician Descriptopns

    The Code contained in the titles.html file (main file, displayed in the framework on the right) is roughly as follows:


    Toshiko Akiyoshi

    Interlude

    The Beatles

    Please Me

    Betty Carter

    Ray Charles and Betty Carter
    ...

    For details about the create frame syntax, see frame object.



    --------------------------------------------------------------------------------



    Reference window and frame
    The name of the window to reference depends on whether you want to reference the properties, methods, and event handlers of the window, or use the window as an object for form submission or hypertext chain.

    Because the window object is located at the top of the JavaScript client hierarchy, window is the basis for describing the inclusion relationship between objects in the window.

    Reference window properties, methods, and event handlers
    You can use either 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 and both indicate the current window. You can select either of them to reference 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 window name. top refers to the top-level Navigator window. parentrefers to the window containing frameset.for example, the sentence parent.frame2.doc ument. bgColor = "teal" sets the background color of the frame named frame2 to teal. frame2 is a frame of the current frameset.
    Window variable name: the variable name specified when the window is opened. for example, msgWindow. close to close the window named msgWindow. however, to open or close a window in the event handler, you must use window. open () or window. close (), but not open () and close (). due to the scope of static objects in JavaScript, calling close without specifying the object name is equivalent to document. close ().
    The window name is omitted because the current window is always assumed. When you call the window method and use its properties, You can omit the window name. For example, close () closes the current window.
    For more information about window methods, see window object

    Example 1 reference the current window. The following statement references the form named musicform in the current window. If the check box is checked, this statement displays a warning.

    If (self.doc ument. musicForm. checkbox1.checked)
    Alert ('the checkbox on The misicForm is checked ')

    Example 2 reference other windows. the following statement references the form named musicform in the window checkboxWin. these statements verify whether the check box is checked. Execute the check box to check whether an option of the select object is selected and SELECT an option of the select object.

    // Check whether the check box is checked
    If (checkboxWin.doc ument. musicForm. checkbox2.checked ){
    Alert ('the checkbox on The misicForm in checkboxWin is checked ')}

    // Execute the check box
    CheckboxWin.doc ument. musicForm. checkbox2.checked = true

    // Determine whether an option of the select object is selected
    If (checkboxWin.doc ument. musicForm. musicTypes. options [1]. selected)
    Alert ('option 1 is selected! ')

    // SELECT an option for the SELECT object
    CheckboxWin.doc ument. musicForm. musicTypes. selectedIndex = 1

    Example 3 references frame in another window. The following statement references frame named frame2 in window window2. this statement changes the background color of frame2 to purple, and the name of frame2 must beMarked.Can generate frameset.

    Window2.frame2.doc ument. bgColor = "violet"

    Reference a window in form submission or hypertext chain
    When a window is used as an object for form submission or hypertext chain (

    Or marked TARGET attribute). You must use the window name instead of the window variable. This window will be a chain loaded window, or for form, it is a window showing the server response.

    Example 1 window 2. The example below creates a hypertext chain for the second window. In this example, a button is used to open a window named window2, and the doc2.html file is mounted to the latest window. In addition, the button is used to close the window.


    OnClick = "msgWindow = window. open ('', 'resizable = no, width = 200, height = 100 ')"


    OnClick = "msgWindow. close ()">

    Example 2 anchor.in the second window, create a superchain for anchor.this chain is connected to anchor named number in doc2.html in window2.

    Numbers

    Example 3: frame name. The next example is the frame's anchorcreated A superchain.this chain is named contframedisplay file sesame.html named abs_method. This frame must be placed in the current frameset, and the frame name must be usedThe NAME attribute definition of the tag.

    Abs

    Example 4 name of a regular frame. in the following example, the contents of the file artists.html are displayed in the parent window of the current frameset. The link object appears in a frame of the frameset. When you press this link, all frames in the frameset disappear, artists. the ftml content is loaded into the parent window.


    Musician Descriptions



    --------------------------------------------------------------------------------



    Navigating among windows)
    Multiple Navigator windows can be opened at the same time. you can press the window to focus the window to browse between these windows. you can focus on objects in a window by programming, or specify this window as the object of the Super Text chain. although you can change the object Value in the second window, the second window cannot be activated, and the current window is always active.

    An activity window is a window with focus. Once the window has focus, the window is placed at the beginning and can be changed visually. for example, the title bar of the window can change the color. the visual effect varies with your platform.

    Example 1 assign focus to an object in another window. the following statement assigns focus to the text object city in the window checkboxWin. Because the city gets the focus, checkboxWin gets the focus and becomes the activity window. this example also contains the statement for creating checkboxWin.

    CheckboxWin = window. open ("doc2.html ")
    ...
    CheckboxWin.doc ument. musicForm. city. focus ()

    Example 2 Use hypertext chains to assign focus to another window. the following sentence specifies window2 as the object of the hypertext chain. When you press this link, the focus is converted to window2. if window2 does not exist, it is created.

    Load a file into window2

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.