Web hosting comparison - 125Chapter 11Scripting Frames and Multiple WindowsFrame Scripting TipsOne

125Chapter 11Scripting Frames and Multiple WindowsFrame Scripting TipsOne of the first mistakes that frame scripting newcomers make is writing immediate scriptstatements that call upon other frames while the pages load. The problem here is that youcannot rely on the document loading sequence to follow the frameset source code order. Allyou know for sure is that the parent document beginsloading first. Regardless of the order oftags, child frames can begin loading at any time. Moreover, a frame s loading timedepends on other elements in the document, such as images or Java applets. Fortunately, you can use a certain technique to initiate a script once all of the documents inthe frameset are completely loaded. Just as the onloadevent handler for a document fireswhen that document is fully loaded, a parent s onloadevent handler fires after the onloadevent handler in its child frames is fired. Therefore, you can specify an onloadevent handlerin the tag. That handler might invoke a function in the framesetting documentthat then has the freedom to tap the objects, functions, or variables of all frames throughoutthe object hierarchy. Make special note that a reference to a frame as a type of window object is quite separatefrom a reference to the frameelement object. An element object is one of those DOM elementnodes in the document node tree (see Chapter 4). The properties and methods of this nodediffer from the properties and methods that accrue to a window-type object. It may be a diffi- cult distinction to grasp, but it s an important one. The way you reference a frame as a win- dow object or element node determines which set of properties and methods are availableto your scripts. See Chapter 15 for a more detailed introduction to element node scripting. If you start with a reference to the frameelement object, you can still reach a reference to thedocumentobject loaded into that frame. But the syntax is different depending on the browser. IE4+ and Safari let you use the same documentreference as for a window; Mozilla-basedbrowsers follow the W3C DOM standard more closely, using the contentDocumentpropertyof the frame element. To accommodate both syntaxes you can build a reference as follows: var docObj; var frameObj = document.getElementById( myFrame ); if (frameObj.contentDocument) { docObj = frameObj.contentDocument; } else { docObj = frameObj.document; } About iframe ElementsThe iframeelement is supported as a scriptable object in IE4+, Mozilla-based browsers, andSafari (among other modern browsers). It is often used as a way to fetch and load HTML orXML from a server without disturbing the current HTML page. Therefore it s not uncommonfor an iframeto be hidden from view, while scripts handle all of the processing between itand the main document. An iframeelement becomes another member of the current window s framescollection. Butyou may also reference the iframeas an element object through W3C DOM document. getElementById()terminology. As with the distinction between the traditional frame-as- window object and DOM element object, a script reference to the documentobject within aniframeelement object needs special handling. See Chapter 16 for additional details.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

Leave a Reply