please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 11
Windows and the JavaScript Name Space
Next
 

11.4 Window and Frame Names

The second, optional[1] argument to the open() method discussed earlier is a name for the newly created window. By giving a top-level browser window a name, we've seen that you can look up a reference to that window by calling the open() method again. But you can also refer to a window by name in another way: by specifying the window name as the value of the TARGET attribute of the <A>, <MAP>, and <FORM> tags. What this does is tell the browser where you want the results of activating a link, clicking on an image map, or submitting a form to be displayed. For example, if you have two windows, one named "table_of_contents" and the other named "mainwin", then you might have HTML like the following in the "table_of_contents" window:

<A HREF="chapter01.html" TARGET="mainwin">
Chapter 1, Introduction
</A>
When the user clicks on this hyperlink, the browser will load the specified URL, but instead of displaying it in the window the link is in, it will display it in the window named "mainwin". If there is no window with the name "mainwin", then clicking on the link will create a new window with that name, and load the specified URL into it.

[1] This argument is not optional in Internet Explorer 3.0.

Since frames are a type of window, frames can also have names that can be used with the TARGET attribute. You specify a name for a frame with the NAME attribute of the <FRAME> tag that creates the frame.

There is even another reason to give names to frames. We've seen that every Window object has a frames[] array that contains references to each of its frames. This array contains all frames in a window (or frame) whether or not they have names. But if a frame is given a name, then a reference to that frame is also stored in a new property of the parent Window object. The name of that new property is the same as the name of the frame. Therefore, if you create a frame with HTML like this:

<FRAME NAME="table_of_contents" SRC="toc.html">
Then you can refer to that frame from another, sibling frame with:

parent.table_of_contents
This makes your code easier to read and understand than using (and relying on) a hardcoded array index as you'd have to do with an unnamed frame:

parent.frames[1]

Much of the discussion in this section has been about the TARGET attribute and other features of HTML rather than about JavaScript itself. If windows can have names, then it is logical to expect that Window objects have a JavaScript property that contains the window name. This is indeed true. The name property of any Window object contains the name of that window. In Navigator 2.0, this property is read-only. In Navigator 3.0, however, you can set this property, thereby changing the name of a window or a frame. One common reason to do this is to set the name of the initial browser window. When Navigator starts up, the initial window has no name, and so it cannot be used with the TARGET attribute. If you set the name property of the window, however, you can then use that name in TARGET attributes.


Previous Home Next
Windows and Frames Book Index The JavaScript Name Space

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/ch11_04.htm, 7KB, , updated: 2019/10/14 15:00, local time: 2024/12/27 14:43,
TOP NEW HELP FIND: 
3.137.198.181:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://linistepper.com/techref/language/java/script/definitive/ch11_04.htm"> [Chapter 11] 11.4 Window and Frame Names</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?