Home Resources Bio Meet the Family
JavaScript
Frames: Target Practice
Target is used to indicate where the hyperlink will be displayed in reference to the current window or frame. This could be the same window, a new window, or one of the frames on a multi-frame display. Here are two examples:
    <a href="something.html"> – displays hyperlink in current window
    <a href="something.html" target="content"> – displays hyperlink in frame named "content"
Values for target may be:
    _top (removes all frames)
    _parent (updates parent frame if this is a child, otherwise updates itself)
    _self (updates frame containing the hyperlink)
    _blank (displays in new, unnamed window)
    xxx (displays in the frame named "xxx")

    If there is no "target" identified in the tag, then the hyperlink displays in the current window.
This is basic HTML. So, what does it have to do with JavaScript? Sometimes, you want the target to change, but there is no href tag involved. Imagine that you have a frameset with 3 frames: the titlebar, a welcome message area, and a content area.

As different pages are displayed in the content area, you want different messages to appear. The following code, placed in the content area, would cause the file "hello.htm" to display in the welcome message area:
    <script language="JavaScript">
    if (window.top.frames.length>0){window.top.frames[1].location="hello.htm"}
    </script>
The location being set is the name of the page you want to access. The value "frames[0]" is the first frame defined in the frameset. Next one would be "frames[1]" and then "frames[2]", depending on how many frames you've defined in the frameset.