Archive for February, 2008

378Part IIIDocument Objects Referencedifferent document into a (Best web hosting site) window,

Wednesday, February 6th, 2008

378Part IIIDocument Objects Referencedifferent document into a window, use the locationobject (see Chapter 17). The documentobject is described in detail in Chapter 18. Related Items:documentobject. eventValue:Object.Read/WriteCompatibility:WinIE4+, MacIE4+, NN-, Moz-, Safari1+ IE4+ and Safari treat the eventobject as a property of the windowobject. Navigator 4+ andthe W3C DOM (as well as Safari here, too) pass an instance of the Eventobject as an argu- ment to event handler functions. The connection with the windowobject is relatively inconse- quential, because all action involving the eventobject occurs in event handler functions. Theonly difference is that the object can be treated as a more global object when one event han- dler function invokes another. Instead of having to pass the eventobject parameter to thenext function, functions can access the eventobject directly (with or without the window. prefix in the reference). For complete details about the eventobject in all browsers, see Chapter 25. Related Items:eventobject. externalValue:Object.Read-OnlyCompatibility:WinIE4+, MacIE-, NN-, Moz-, Safari- The externalproperty is useful only when the browser window is a component in anotherapplication. The property provides a gateway between the current browser window and theapplication that acts as a host to the browser window component. With WinIE4+ acting as a component to the host operating system, the externalproperty canbe used to access several methods that influence behaviors outside of the browser. Perhapsthe three most useful methods to regular Web page scripters are AddDesktopComponent(), AddFavorite(), and NavigateAndFind(). The first two methods display the same kind ofalert dialog box that users get after making these choices from the browser or desktop menus, so that you won t be able to sneak your Web site onto desktops or Favorites listings withoutthe visitor s approval. Table 16-2 describes the parameters for these three methods. Table 16-2: Popular window.external Object MethodsMethodDescriptionAddDesktopComponentAdds a Web site or image to the Active Desktop (if turned on in the ( URL , type [, user s copy of Windows). The typeparameter value is either left, top, width, websiteor image. Dimensional parameters (optional) are all height])integer values. AddFavoriteAdds the specified URL to the user s Favorites list. The optional title( URL [, title ])string parameter is how the URL should be listed in the menu (ifmissing, the URL appears in the list). NavigateAndFindNavigates to the URL in the first parameter and opens the page in ( URL , findString , the target frame (an empty string opens in the current frame). The target )findStringis text to be searched for on that page andhighlighted when the page loads. windowObject.document

377Chapter 16Window and Frame Objectsbar.visible = !bar.visible; netscape.security.PrivilegeManager.revertPrivilege( (Web hosting script)

Tuesday, February 5th, 2008

377Chapter 16Window and Frame Objectsbar.visible = !bar.visible; netscape.security.PrivilegeManager.revertPrivilege( UniversalBrowserWrite ); } // restore settingsfunction restore() { netscape.security.PrivilegeManager.enablePrivilege( UniversalBrowserWrite ); window.locationbar.visible = originalLocationbar; window.menubar.visible = originalMenubar; window.personalbar.visible = originalPersonalbar; window.scrollbars.visible = originalScrollbars; window.statusbar.visible = originalStatusbar; window.toolbar.visible = originalToolbar; netscape.security.PrivilegeManager.revertPrivilege( UniversalBrowserWrite ); }

Toggle Window Bars








Related Items:window.open()method. documentValue:Object.Read-OnlyCompatibility:WinIE3+, MacIE3+, NN2+, Moz1+, Safari1+ I list the documentproperty here primarily for completeness. Each windowobject contains asingle documentobject (although in Navigator 4, a window may also contain layers, each ofwhich has a documentobject, as described in Chapter 39 on the CD-ROM). The value of thedocumentproperty is the documentobject, which is not a displayable value. Instead, you usethe documentproperty as you build references to properties and methods of the documentand to other objects contained by the document, such as a form and its elements. To load awindowObject.document

376Part IIIDocument Objects ReferenceNavigator 4 promoted these elements (Web site designers)

Tuesday, February 5th, 2008

376Part IIIDocument Objects ReferenceNavigator 4 promoted these elements to first-class objects contained by the windowobject. Navigator 6 added one more feature, called the directories bar a frame-like device that canbe opened or hidden from the left edge of the browser window. At the same time, however, NN6+/Mozilla browsers no longer permit hiding and showing the browser window s scroll- bars. Chrome objects have but one property: visible. Reading this Boolean value (possiblewithout signed scripts) lets you inspect the visitor s browser window for the elements cur- rently engaged. Changing the visibility of these items on the fly alters the relationship between the inner andouter dimensions of the browser window. If you must carefully size a window to display con- tent, you should adjust the chrome elements before sizing the window. Before you startchanging chrome visibility before the eyes of your page visitors, weigh the decision carefully. Experienced users have fine-tuned the look of their browser windows to just the way they likethem. If you mess with that look, you may anger your visitors. Fortunately, changes you maketo a chrome element s visibility are not stored to the user s preferences. However, thechanges you make survive an unloading of the page. If you change the settings, be sure youfirst save the initial settings and restore them with an onunloadevent handler. The Macintosh menu bar is not part of the browser s window chrome. Therefore, its visibilitycannot be adjusted from a script. ExampleIn Listing 16-6, you can experiment with the look of a browser window with any of the chromeelements turned on and off. To run this script, you must either sign the scripts or turn oncodebase principals (see Chapter 46 on the CD-ROM). Java must also be enabled to use thesigned script statements. As the page loads, it stores the current state of each chrome element. One button for eachchrome element triggers the toggleBar()function. This function inverts the visible propertyfor the chrome object passed as a parameter to the function. Finally, the Restore buttonreturns visibility to their original settings. Notice that the restore()function is also calledby the onunloadevent handler for the document. Also, if you load this example into NN6+, non-fatal script errors occur when the scrollbars are turned on or off. Listing 16-6:Controlling Window Chrome Microsoft

Mozilla

windowObject.defaultStatus

Yahoo free web hosting - 372Part IIIDocument Objects ReferenceListing 16-4:Checking Before Closing a

Saturday, February 2nd, 2008

372Part IIIDocument Objects ReferenceListing 16-4:Checking Before Closing a Window


To complete the example of the window opening and closing, notice that the subwindow isgiven a button whose onclickevent handler closes the main window. In modern browsers, the user is presented with an alert asking to confirm the closure of the main browser window. Related Items:window.open(), window.close()methods. Components(See appCore) controllers(See appCore) windowObject.closed

371Chapter 16Window and Frame ObjectsYou cannot use the (Dedicated web hosting)

Friday, February 1st, 2008

371Chapter 16Window and Frame ObjectsYou cannot use the clipboardDataobject to transfer data between pages that originate fromdifferent domains or arrive via different protocols (httpversus https). ExampleSee Listings 15-30 and 15-39 to see how the clipboardDataobject is used with a variety ofedit-related event handlers. Related Items:event.dataTransferproperty; onbeforecopy, onBeforeCut, onbeforepaste, oncopy, oncut, onpasteevent handlers. closedValue:Boolean.Read-OnlyCompatibility:WinIE4+, MacIE4+, NN3+, Moz1+, Safari1+ When you create a subwindow with the window.open()method, you may need to accessobject properties from that subwindow, such as setting the value of a text field. Access to thesubwindow is via the windowobject reference that is returned by the window.open() method, as in the following code fragment: var newWind = window.open( someURL.html , subWind ); … newWind.document.entryForm.ZIP.value = 00000 ; In this example, the newWindvariable is not linked live to the window, but is only a refer- ence to that window. If the user should close the window, the newWindvariable still containsthe reference to the now missing window. Thus, any script reference to an object in that miss- ing window will likely cause a script error. What you need to know before accessing items inasubwindow is whether the window is still open. The closedproperty returns trueif the windowobject has been closed either by script orbythe user. Any time you have a script statement that can be triggered after the user has anopportunity to close the window, test for the closedproperty before executing thatstatement. ExampleIn Listing 16-4, I have created a basic window opening and closing example. The script beginsby initializing a global variable, newWind, which is used to hold the object reference to thesecond window. This value needs to be global so that other functions can reference the win- dow for tasks, such as closing. For this example, the new window contains some HTML code written dynamically to it, ratherthan loading an existing HTML file into it. Therefore, the URL parameter of the window.open() method is left as an empty string. Next comes a brief delay to allow Internet Explorer (espe- cially versions 3 and 4) to catch up with opening the window so that content can be writtento it. The delay (using the setTimeout()method described later in this chapter) invokes thefinishNewWindow()function, which uses the global newWindvariable to reference the win- dow for writing. The document.close()method closes writing to the document a differentkind of close than a window close. A separate function, closeWindow(), is responsible forclosing the subwindow. As a final test, an ifcondition looks at two conditions: 1) if the windowobject has ever beeninitialized with a value other than null(in case you click the window closing button beforeever having created the new window) and 2) if the window s closedproperty is nullorfalse. If either condition is true, the close()method is sent to the second window. windowObject.closed