HTML The Definitive Guide (145 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
11.15Mb size Format: txt, pdf, ePub

Finally, some images have a pure background color, but that color is also used in parts of the image you want to keep opaque. Since every pixel having the appropriate colormap index is made transparent, these portions of the image become transparent as well.

In all cases, the problem can be solved by loading the image into an image editor, turning off dithering, and painting the background areas, usually by hand, to be a single color not used anywhere else in the image. Make sure you save the result as a GIF image, so that the colormap and pixel indexes will be retained.

15.5.3 Converting the Image

Once you have an acceptable image, and you've determined the color you wish to make transparent, you'll need to convert the image to GIF89a format.

For PC and Unix users, a public-domain utility called giftrans does the job nicely. To convert an image, use this command:

giftrans -t index original.gif > new.gif Replace index with the numeric index of the color to be made transparent. Original.gif and new.gif are the original nontransparent image and the resulting transparent image.

Apple Macintosh users have the advantage, though: they can use a single tool named Transparency to accomplish the conversion. It was written by Aaron Giles at Cornell University, who generously makes it available at no charge over the Internet. Check Yahoo! or your favorite Archie resource to locate it on a server near you.

These tools can do far more than simply convert transparent images. For a complete discussion of transparency and image conversion, including links to the actual tools, visit:
http://members.aol.com/htmlguru/transparent_images.html

15.4 Tricks with Tables

15.6 Tricks with Windows

and Frames

Chapter 15

Tips, Tricks, and Hacks

 

15.6 Tricks with Windows and Frames

For the vast majority of links in your documents, you'll want the newly loaded document displayed in the same window, replacing the previous one. That makes sense, since your users usually follow a sequential path through your collection.

But sometimes it makes sense to open a document in a new window, so that the new document and the old document are both directly accessible on the user's screen. If the new document is related to the original, for instance, it makes sense to have both in view. Other times, you might want to open more than one document in multiple windows in a frameset. More commonly, the new document starts the user down a new web of documents, and you want them to see and remember where they came from.

Regardless of the reason, it is easy to open a new browser window from your HTML document. All you need to do is add the target attribute in the appropriate hyperlink () tag.

15.6.1 Targeting Windows

We normally use the target attribute to load a document into a specific frame that you've named in a frameset. It also serves to create a new window by one of two methods: Reference a new name. If you haven't previously defined a name and then use that new name as the value for the ●

target attribute of a hyperlink, Netscape and Internet Explorer automatically create a new window with that name and load the referenced document into that window. This is the preferred way to create new windows, since you can subsequently use the name to load other documents into the same window. Using this technique, you can control which document gets loaded where.

Create an unnamed window. Some browsers like Netscape and Internet Explorer support a special target named ●

_blank
[3
] that lets you create a new window. The _blank window has limited use, though, because it is nameless - you cannot direct any other documents into that window. (New documents loaded via hyperlinks selected by the user within the window get displayed in that same window, of course.) [3] Some browsers also accept the name
new. If you can't get
blank to work with your browser, try _new.

15.6.2 Overriding Others' Targets

Ever visited a site whose homepage is a frame document that never gives up? You know, the kind that leave their great big logo on the top of the window and their site TOC running down the side of the display, staring you in the face long after you've hyperlinked away from their site? What if your site's frameset gets trapped into one of their window frames? What to do? (Apparently their webmasters hadn't heard about the _blank target.) The short answer is to use JavaScript to force open a new window for your documents. But that, too, is potentially confusing for users, since they may already have a full window ready for your document. So, to embellish, let JavaScript discover whether your page is destined for a corner frame, or for the whole window.

Here is an example script that loads a webpage called
index2.html
into its own full window. Note that the JavaScript-enabled browsers won't let you clear a previously loaded document display unless your document owns it. So, in the case where the target is not the whole window ("self" is not "window.top"), the example script opens a new window that becomes the target for your pages. The user may choose to close your document window and return to the other one, or vice versa:


I need a window of my own



Your browser apparently doesn't support JavaScript. Please hyperlink to our site manually.


15.6.3 Multiple Frames in One Link

Loading a new document from a hyperlink is a snap, even if you put the new document into an alternative frame or window from its hyperlink parent. Occassionally, though, you'll want to load documents into two frames when the user clicks just one link. With a bit of trickery you can load two or more frames at one time, provided they are arranged a certain way in the browser window.

Consider this frame layout:











If someone clicks a link in frame A, the only thing you can do is update one of the four frames. Suppose you wanted to update frames B and D at the same time?

The trick is to replace frames B and D with a single frame, like this:







Ahah! Now you have a single target in which to load a single document, frame BD. The document you load should contain the original frames B and D in one column, like this:




The two frames will fill frame BD. When you update frame BD, both frames will be replaced, giving the appearance of

Other books

White Lion's Lady by Tina St. John
Polychrome by Joanna Jodelka
Dead Sleeping Shaman by Elizabeth Kane Buzzelli
Finding Destiny by Christa Simpson
Die Blechtrommel by Günter Grass
oneforluck by Desconhecido(a)
Cutting Loose by Tara Janzen
The Body in the Piazza by Katherine Hall Page