Web host sites - 85Chapter 8Window and Document ObjectsA windowobject also has
85Chapter 8Window and Document ObjectsA windowobject also has a synonym when the script doing the referencing points to the win- dow that houses the document. The synonym is self. Reference syntax then becomesself.propertyNameself.methodName([parameters]) You can use these initial reference object names interchangeably, but I tend to reserve theuse of selffor more complex scripts that involve multiple frames and windows. The selfmoniker more clearly denotes the current window holding the script s document. It makesthe script more readable by me and by others. Back in Chapter 4, I indicated that because the windowobject is always there when a scriptruns, you could omit it from references to any objects inside that window. Therefore, the fol- lowing syntax models assume properties and methods of the current window: propertyNamemethodName([parameters]) In fact, as you will see in a few moments, some methods may be more understandable if youomit the windowobject reference. The methods run just fine either way. Creating a windowA script does not create the main browser window. A user does that by virtue of launchingthe browser or by opening a URL or file from the browser s menus (if the window is notalready open). But a script can generate any number of subwindows once the main window isopen (and that window contains a document whose script needs to open subwindows). The method that generates a new window is window.open(). This method contains up tothree parameters that define window characteristics, such as the URL of the document toload, its name for targetattribute reference purposes in HTML tags, and physical appear- ance (size and chrome contingent). I don t go into the details of the parameters here (they recovered in great depth in Chapter 16), but I do want to expose you to an important conceptinvolved with the window.open()method. Consider the following statement that opens a new window to a specific size and with anHTML document from the same server directory that holds the current page: var subWindow = window.open( define.html , def , height=200,width=300 ); The important thing to note about this statement is that it is an assignment statement. Something gets assigned to that variable subWindow. What is it? It turns out that when thewindow.open()method runs, it not only opens up that new window according to specifica- tions set as parameters, but it also evaluates to a reference to that new window. In program- ming parlance, the method is said to return a value in this case, a genuine object reference. The value returned by the method is assigned to the variable. Your script can now use that variable as a valid reference to the second window. If you needto access one of its properties or methods, you must use that reference as part of the com- plete reference. For example, to close the subwindow from a script in the main window, usethis reference to the close()method for that subwindow: subWindow.close();
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services