Friday, November 27, 2009

Section 5.1. Hidden Frames and iframes










5.1. Hidden Frames and iframes


Frames and iframes (in-line frames), for some reason, are one of those things that strike fear into the heart of web developers everywhere. It is one of those deep-seated fears, like tanning products are to a vampire or advertisements for having your pet spayed or neutered are to a werewolf. Several reasons for this primal fear of frames exist; fortunately, there is a countermeasure for each of these reasons.


The first of these reasons is the mistaken belief that frames are nonstandard and, therefore, are supported by only a handful of "unholy" web browsers. Fortunately, this belief is a total and complete myth because frames and iframes have the blessing of the World Wide Web Consortium. In fact, the only unholyeh, make that unusualpart is that the frames are hidden, but, then, that's the entire point of this endeavor.


Now let's get into the actual specifics of making frames behave like Claude Rains, who, if I may digress for a moment, brilliantly played a mad scientist even if he didn't start that way. First starting with the older frame instead of the more recent iframe, the hiding entirely takes place in the frameset, as Listing 5-1 shows.


Listing 5-1. The Older Frame





<frameset rows="100%,*">
<frame name="visible_frame" src="visible.htm">
<frame name="hidden_frame" src="hidden.htm">
<noframes>
Frames are required to use this web site.
</noframes>
</frameset>




As mentioned in the previous chapter, the rows="100%,*" performs the magic, but it isn't the only method available to us. In fact, looking at only the opening frameset tag, the following eight examples all produce the desired results:


<frameset rows="100%,*">

<frameset rows="100%,0">

<frameset rows="*,0%">

<frameset rows="*,0">

<frameset cols="100%,*">

<frameset cols="100%,0">

<frameset cols="*,0%">

<frameset cols="*,0">


The reason for this plethora of choices is that this is one of those times when we really don't care how the hiding is accomplishedall that matters is that the hiding is accomplished. Oh, this is a good time for me to point out that when developing a new application using hidden frames, it isn't a violation of the mad scientist rules to make the hidden frame visible for testing. It is, however, a violation to let others see the frame with the hidden frame visible, both because it gives the impression that something is wrong with our fiendish plans and because it looks ugly.


Unlike framesets, in which the hiding is accomplished through the use of either rows or columns, iframes have the much-easier-to-remember height and width attributes, as the following tag shows:


<iframe height="0" width="0" src="hidden.htm">


That's itjust the one measly little tag, and we've got something that kind of looks a lot like Ajax. Right about now you're either taking my name in vain or wondering why I didn't start with iframes. In fact, there are probably some out there who are doing both. Well, the answer is both personal and simple. Whenever I learn something new, I try to immerse myself totally in it, avoiding all shortcuts until whatever I learned becomes second nature. To be totally honest, after learning to swim, I was wrinkled for a week.












No comments: