in black and white
Main menu
Home About us Share a book
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Javascript for dummies 4th edition - Veer E.V

Veer E.V Javascript for dummies 4th edition - Wiley publishing , 2004. - 387 p.
ISBN: 0-7645-7659-3
Download (direct link): javascriptfordummies2005.pdf
Previous << 1 .. 49 50 51 52 53 54 < 55 > 56 57 58 59 60 61 .. 118 >> Next

In the example in this section, the content in the frame on the right reloads based on what a user clicks in the left frame. So, naturally, the code that’s responsible for the text reload can be found in the source code for the left frame, pub_l.htm. Take a look at the pertinent syntax shown in Listing 7-4. This code snippet, from pub_l.htm, connects the table of contents links to the appropriate content.
Listing 7-4: Connecting the Index Links to the Content Headings
// When a user clicks the Introduction link, // the anchor located at pro_c.htm#top loads into the // frame named content
<A HREF=”pro_c.htm#top” TARGET=”content” >Introduction</A>
// When a user clicks the Why Can't I Get Published? l // the anchor located at pro_c.htm#cantget loads into // frame named content ink, the
<A HREF=”pub_c.htm#cantget” TARGET=”content” >Why can't I get published?</A>
<A HREF=”pub_c.htm#rescue” TARGET=”content” >E-publishing to the rescue!</A>
<A HREF=”pub_c.htm#types” TARGET=”content” >The 3 types of e-publishers</A>
<A HREF=”pub_c.htm#choose” TARGET=”content” >Choosing an e-publisher</A>
<A HREF=”pub_c.htm#epubGuide” TARGET=”content” >What Every Writer MUST Know About E-Publishing</A>
// When a user clicks the " home” link, a // new page (home.htm) replaces the current page
<A HREF=”home.htm” TARGET=”_top” > home</A>
Each of the links that I define in Listing 7-4 contains a value for the TARGET attribute. Except for the last link, the TARGET attribute is set to content — the name of the frame on the right, which is defined in Listing 7-3, shown earlier in this chapter. Assigning the name of a frame to the TARGET attribute of a link causes that link to load in the named frame, just as you see in Figure 7-3, shown previously.
Chapter 7: Working with Browser Windows and Frames 153
Right on target
When you create a link (or an anchor, area, base, or form) in HTML, you have the option of specifying a value for the TARGET attribute associated with these HTML elements. Valid values for the TARGET attribute include any previously named frame or window or one of the following built-in values. (See Chapter 11 for an example of specifying the _top value for the TARGET attribute associated with a link.)
Value What Does It Mean?
_blank Open the link in a brand-new
_parent Open the link in this window or
frame's parent window/frame
_self Open the link in this window or
_top Open the link in the root window or
You might want to handle the final link in the listing a bit differently. At the bottom of Listing 7-4, you see that the last defined link assigns a value of _top to the TARGET attribute. When a user clicks the Home link, the page changes to the contents of home.htm.
_top is a built-in value that translates to “whatever the top-level window in this window/frame hierarchy happens to be.” (The sidebar “Right on target” in this chapter describes all the built-in values that you can specify for the TARGET attribute.)
If you specify a value for TARGET that doesn’t match either a previously defined frame name or one of the built-in values that you see in the sidebar “Right on target,” the associated link loads into a brand-new window. So if you expect a link to open in a frame and it pops up in a new window instead, check your source code. Odds are you made a typo!
The example in this section shows you how to load the contents of one frame based on a user’s clicking a link in another. To load two frames based on a user’s clicking a link, you can create a JavaScript function similar to the following:
function loadTwoFrames(leftURL, contentURL) {
// Loads the first passed-in URL // into the container frame previously defined // as "leftNav" in an HTML file such as the one // you see in Listing 7-3
154 Part II: Creating Dynamic Web Pages
// Loads the second passed-in URL
// into the container frame previously defined
// as "content”
Then pass the loadTwoFrames() function two URL strings. For example:
<A HREF=javascript:loadTwoFrames('some.htm', 'another.htm')”> or
<INPUT TYPE=”button” VALUE=”Load Two Frames” onClick=”loadTwoFrames('some.htm', 'another.htm')”>
Don't fence me in!
Just as you can display other folks' Web pages inside your frames, so those folks can display your Web pages inside their frames.
But in some cases, you might want to prevent your site from being framed. For example, say you spend weeks creating a beautiful, graphics-rich site optimized for a particular monitor size and screen resolution. Then, say I come along and add a link to your site from mine — but I choose to display your fabulous, pixel-perfect site by squeezing it into a tiny 2-x-2-inch frame! (Worse yet, I'm a cat lover, so I surround the 2-x-2-inch frame with an image of my beloved Fifi — so your site appears to be peeking out of my cat's mouth.)
Previous << 1 .. 49 50 51 52 53 54 < 55 > 56 57 58 59 60 61 .. 118 >> Next