DHTML Lab: Dynamic Page Segments; Explorer Initialization
Dynamic Page Segments
| |||
Our technique uses this column's front page as a live example. If you wish to follow the tutorial with the front page visible for reference, you may view it: in a new window (all) When you are done, you may: | Explorer InitializationFilling the arSegments Array allDIVs = document.all.tags("DIV"); Using our trusty for loop, we go through all the elements in allDIVs. First we assign the showIt() method to them. Then we check their style class. If the className property is "segment", then the element is appended to the arSegments array: for (i=0; i<allDIVs.length; i++) { allDIVs(i).showIt = showIt; if (allDIVs(i).className=="segment") arSegments[arSegments.length] = allDIVs[i]; } Looping Through the arSegments Array for (i=0; i<arSegments.length; i++) { tempSeg = arSegments[i]; if (leftPos!=null) tempSeg.style.pixelLeft = leftPos; if (topPos!=null) tempSeg.style.pixelTop = topPos; tempSeg.arrangeIt = arrangeIt; tempSeg.style.width = // keep with next line document.body.clientWidth - leftPos - margRight; } Finally, now that Explorer has determined how wide the body of the document is, since it has parsed the BODY tag, we can dynamically set the width of segment elements with the document.body.clientWidth property. Final Cross-Browser InitializationThe final three statements in initIt() are common to both browsers:if (hasFooter) footerEl = eval(footerEl); currentSeg = eval(prefix + firstSeg) showSegment(firstSeg); If we have a footer, than we evaluate the string stored in footerEl, and assign it right back to footerEl, allowing for easier referencing. For example, if footerEl initially stored "end", as a string, then after the eval() it would store end, as a variable, which would correspond to the one-word cross-browser variable reference we established in the initialization earlier. Next, we create a new variable, currentSeg, that will always store the segment being currently displayed. Since we are starting with the first segment, we concatenate the two string variables, prefix and firstSeg, (in our example page, "seg" and "Intro", respectively), evaluate them and store the resulting element reference in currentSeg. Finally, we call showSegment(), passing the firstSeg string as its sole argument. Our initialization complete, control is thus passed to showSegment(), which will display the first page segment. |
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.Created: Mar. 11, 1998
Revised: Mar. 12, 1998
URL: https://www.webreference.com/dhtml/column16/segInitIE.html