388Part IIIDocument Objects ReferenceListing 16-10(continued) // (Web site templates) turn on

February 13th, 2008

388Part IIIDocument Objects ReferenceListing 16-10(continued) // turn on error dialogs with hard reloadfunction errOn() { window.onerror = handleError; } // assign default error handlerwindow.onerror = handleError; // error handler when errors are turned off…prevents error dialogfunction doNothing() { return true; } function handleError(msg, URL, lineNum) { var errWind = window.open( , errors , height=270,width=400 ); var wintxt = ; wintxt += An error has occurred on this page. Please report it to Tech Support. ; wintxt +=

; wintxt +=
; wintxt += ; wintxt += ; wintxt +=

; errWind.document.write(wintxt); errWind.document.close(); return true; }

387Chapter 16Window and Frame ObjectsWhen the browser starts, (Web hosting comparison)

February 13th, 2008

387Chapter 16Window and Frame ObjectsWhen the browser starts, the window.onerrorproperty is . In this state, allerrors are reported via the normal JavaScript error window or message. To turn off erroralerts, set the window.onerrorproperty to invoke a function that does absolutely nothing: function doNothing() { return true; } window.onerror = doNothing; To restore the error messages, reload the page. You can, however, also assign a custom function to the window.onerrorproperty. This func- tion then handles errors in a more friendly way under your script control. Whenever errormessages are turned on (the default behavior), a script error (or Java applet or class excep- tion) invokes the function assigned to the onerrorproperty, passing three parameters: .Error message .URL of document causing the error .Line number of the errorYou can essentially trap for all errors and handle them with your own interface (or no usernotification at all). The last statement of this function must be return trueif you do notwant the JavaScript script error message to appear. If you are using LiveConnect to communicate with a Java applet directly from your scripts, you can use the same scheme to handle any exception that Java may throw. A Java exceptionis not necessarily a mistake kind of error: Some methods assume that the Java code will trapfor exceptions to handle special cases (for example, reacting to a user s denial of access whenprompted by a signed script dialog box). See Chapter 44 on the CD-ROM for an example oftrapping for a specific Java exception. Also, see Chapter 31 for JavaScript exception handlingintroduced for W3C DOM compatible browsers. ExampleIn Listing 16-10, one button triggers a script that contains an error. I ve added an error han- dling function to process the error so that it opens a separate window and fills in a textareaform element (see Figure 16-5). A Submit button is also provided to mail the bug informationto a support center e-mail address an example of how to handle the occurrence of a bug inyour scripts. Listing 16-10:Controlling Script Errors
Setting Inner Sizes




Setting Outer Sizes







Related Items:window.resizeTo(), window.moveTo()methods; screenobject; navigatorobject. loadingValue:Boolean.Read-OnlyCompatibility:WinIE-, MacIE-, NN4, Moz-, Safari- This NN4-specific property allows you to query whether the window is still loading content. The property returns trueif the page is still loading and falseif the page has completedloading all of its content. windowObject.innerHeight

383Chapter 16Window and Frame ObjectsSupporting browsers provide two (Vps web hosting)

February 10th, 2008

383Chapter 16Window and Frame ObjectsSupporting browsers provide two different points of reference for measuring the height andwidth of a window: inner and outer. Both are measured in pixels. The inner measurements arethat of the active document area of a window (sometimes known as a window s contentregion). If the optimum display of your document depends on the document display areabeing a certain number of pixels high and/or wide, the innerHeightand innerWidthproper- ties are the ones to set. In contrast, the outer measurements are of the outside boundary of the entire window, includ- ing whatever chrome is showing in the window: scroll bars, status bar, and so on. Setting theouterHeightand outerWidthis generally done in concert with a reading of screenobjectproperties (see Chapter 38 on the CD-ROM). Perhaps the most common usage of the outerproperties is to set the browser window to fill the available screen area of the visitor s monitor. A more efficient way of modifying both outer dimensions of a window is with thewindow.resizeTo()method, which is also available in IE4+. The method takes pixel widthand height (as integer values) as parameters, thus accomplishing a window resizing in onestatement. Be aware that resizing a window does not adjust the location of a window. Therefore, just because you set the outer dimensions of a window to the available spacereturned by the screenobject doesn t mean that the window will suddenly fill the availablespace on the monitor. Application of the window.moveTo()method is necessary to ensurethe top-left corner of the window is at screen coordinates 0,0. Despite the freedom that these properties afford the page author, Netscape and Mozilla-basedbrowsers have built in a minimum size limitation for scripts that are not cryptographicallysigned. You cannot set these properties such that the outer height and width of the window issmaller than 100 pixels on a side. This limitation is to prevent an unsigned script from settingup a small or nearly invisible window that monitors activity in other windows. With signedscripts, however, windows can be made smaller than 100 100 pixels with the user s permis- sion. IE4+ maintains a smaller minimum size to prevent resizing a window to zero size. Users may dislike your scripts messing with their browser window sizes and positions. NN7+/Moz1+/Safari do not allow scripts to resize windows. ExampleIn Listing 16-9, a number of buttons let you see the results of setting the innerHeight, innerWidth, outerHeight, and outerWidthproperties in NN4 and NN6. Later browsers andSafari ignore scripted adjustments to these properties. Listing 16-9:Setting Window Height and Width The last statement in the example shows how to use the array syntax (brackets) to refer to aspecific frame. All array indexes start with 0 for the first entry. Because the document asksfor the name of the first frame (parent.frames[0]), the response is JustAKid1for bothframes. Related Items:frame, framesetobjects; window.parent, window.topproperties. windowObject.frames

Medical web site - 380Part IIIDocument Objects ReferenceTo use the framesproperty to

February 8th, 2008

380Part IIIDocument Objects ReferenceTo use the framesproperty to communicate from one frame to another, it should be part of areference that begins with the parentor topproperty. This lets JavaScript make the properjourney through the hierarchy of all currently loaded objects to reach the desired object. Tofind out how many frames are currently active in a window, use this expression: parent.frames.lengthThis expression returns a number indicating how many frames the parent window defines. This value does not, however, count further nested frames, should a third generation of framebe defined in the environment. In other words, no single property exists that you can use todetermine the total number of frames in the browser window if multiple generations offrames are present. The browser stores information about all visible frames in a numbered (indexed) array, withthe first frame (that is, the topmost tag defined in the framesetting document) asnumber 0: parent.frames[0] Therefore, if the window shows three frames (whose indexes are frames[0], frames[1], andframes[2], respectively), the reference for retrieving the titleproperty of the document inthe second frame isparent.frames[1].document.titleThis reference is a road map that starts at the parent window and extends to the secondframe s document and its titleproperty. Other than the number of frames defined in a par- ent window and each frame s name (top.frames[i].name), no other values from the framedefinitions are directly available from the frame object via scripting until you get to IE4 andNN6/W3C (see the frameelement object later in this chapter). In these browsers, individualframeelement objects have several properties that reveal tag attributes. Using index values for frame references is not always the safest tactic, however, becauseyourframeset design may change over time, in which case the index values will also change. Instead, you should take advantage of the nameattribute of the tag, and assign aunique, descriptive name to each frame. A value you assign to the nameattribute is also thename that you use for targetattributes of links to force a linked page to load in a frameother than the one containing the link. You can use a frame s name as an alternative to theindexed reference. For example, in Listing 16-7, two frames are assigned distinctive names. Toaccess the title of a document in the JustAKid2frame, the complete object reference isparent.JustAKid2.document.titlewith the frame name (case-sensitive) substituting for the frames[1]array reference. Or, inkeeping with JavaScript flexibility, you can use the object name in the array index position: parent.frames[ JustAKid2 ].document.titleThe supreme advantage to using frame names in references is that no matter how the frame- set structure may change over time, a reference to a named frame will always find that frame, although its index value (that is, position in the frameset) may change. ExampleListings 16-7 and 16-8 demonstrate how JavaScript treats values of frame references fromobjects inside a frame. The same document is loaded into each frame. A script in that docu- ment extracts information about the current frame and the entire frameset. Figure 16-4 showsthe results after loading the HTML document in Listing 16-7. windowObject.frames

379Chapter 16Window and Frame ObjectsExampleThe (Space web hosting) first example asks

February 7th, 2008

379Chapter 16Window and Frame ObjectsExampleThe first example asks the user if it is okay to add a Web site to the Active Desktop. If ActiveDesktop is not enabled, the user is given the choice of enabling it at this point. external.AddDesktopComponent( http://www.nytimes.com , website , 200, 100, 400, 400); In the next example, the user is asked to approve the addition of a URL to the Favorites list. The user can follow the normal procedure for filing the item in a folder in the list. external.AddFavorite( http://www.dannyg.com/update11.html , JSBible 5 Support Center ); The final example assumes that a user makes a choice from a selectlist of items. Theonchangeevent handler of the selectlist invokes the following function to navigate to a fic- titious page and locate listings for a chosen sports team on the page. function locate(list) { var choice = list.options[list.selectedIndex].value; external.NavigateAndFind( http://www.collegesports.net/scores.html , choice, scores ); } frameElementValues:frameor iframeobject reference.Read-OnlyCompatibility:WinIE5.5+, MacIE-, NN-, Moz-, Safari- If the current window exists as a result of a or