368Part IIIDocument Objects ReferenceSyntaxCreating a window: var windowObject (Free web hosting music)

368Part IIIDocument Objects ReferenceSyntaxCreating a window: var windowObject = window.open([parameters]); Accessing window properties or methods: window.property| method([parameters]) self.property| method([parameters]) windowObject.property | method([parameters]) Compatibility:WinIE3+, MacIE3+, NN2+, Moz1+, Safari1+ About this objectThe windowobject has the unique position of being at the top of the object hierarchy, encom- passing even the almighty documentobject. This exalted position gives the windowobject anumber of properties and behaviors unlike those of any other object. Chief among its unique characteristics is that because everything takes place in a window, you can usually omit the windowobject from object references. You ve seen this behavior inprevious chapters when I invoked document methods, such as document.write(). The com- plete reference is window.document.write(). But because the activity was taking place inthe window that held the document running the script, that window was assumed to be partof the reference. For single-frame windows, this concept is simple enough to grasp. As previously stated, among the list of properties for the windowobject is one called self. This property is synonymous with the windowobject itself (which is why it shows up in hier- archy diagrams as an object). Having a property of an object that is the same name as theobject may sound confusing, but this situation is not that uncommon in object-oriented envi- ronments. I discuss the reasons why you may want to use the selfproperty as the window sobject reference in the selfproperty description that follows. As indicated earlier in the syntax definition, you don t always have to specifically create awindowobject in JavaScript code. After you start your browser, it usually opens a window. That window is a valid windowobject, even if the window is blank. Therefore, after a userloads your page into the browser, the windowobject part of that document is automaticallycreated for your script to access as it pleases. One conceptual trap to avoid is believing that a windowobject s event handler or customproperty assignments outlive the document whose scripts make the assignments. Except forsome obvious physical properties of a window, each new document that loads into the win- dow starts with a clean slate of window properties and event handlers. Your script s control over an existing (already open) window s user interface elements varieswidely with the browser and browser version for which your application is intended. Beforethe version 4 browsers, the only change you can make to an open window is to the status lineat the bottom of the browser window. With IE4+ and NN4+, however, you can control suchproperties as the size, location, and (with signed scripts in Navigator and Mozilla) the pres- ence of chrome elements (toolbars and scrollbars, for example) on the fly. Many of theseproperties can be changed beyond specific safe limits only if you cryptographically sign thescripts (see Chapter 46 on the CD-ROM) and/or the user grants permission for your scripts tomake those modifications. window

Leave a Reply