JavaScript: The Definitive Guide

Previous Chapter 12
Programming with Windows
Next
 

12.5 Other Window Programming Techniques

There are a few miscellaneous useful properties and methods of the Window object. The name, opener, and closed properties were already mentioned briefly earlier in this chapter. The name property specifies the name of a window or frame. In Navigator 3.0 (but not Internet Explorer 3.0), this property can be set, thereby changing the window name, which can be useful in conjunction with the TARGET attribute, for example. The opener property is created when a Navigator 3.0 (or Internet Explorer 3.0) browser window is opened--it refers to the window that most recently called the open() method for the window. closed is another Navigator 3.0 property--it specifies whether a window has already been closed. If so, then your JavaScript code should not make any further use of that window.

The focus() and blur() methods of the Window object transfer keyboard focus to, and away from, the window. If you call focus() on a browser window that is currently obscured on the desktop, it will be brought to the top and made visible. These two methods have corresponding onfocus() and onblur() event handlers that are invoked when a window gains or loses focus. Note that blur() and focus() are not supported for Window objects in Internet Explorer 3.0.

The scroll() method scrolls the contents of a window (or frame), just as if the user had used the window's scrollbars explicitly. The two arguments to this method are the absolute X and Y pixel coordinates that the document should be scrolled to. The document in the window moves so that these coordinates are in the upper-left corner of the window. For example, you can more to the top of a document with:

self.scroll(0,0);
If you know you are at the top, and want to scroll down 100 pixels, you might write:

self.scroll(0,100);
Note that the scroll() method is not as useful as it could be because there is no way to find out how big the window is, and there is no way to find out how many pixels tall each line of text is.

Finally, the Window object has a number of other properties, such as document, location and history, and we've seen some of these used in examples in this chapter. These properties, and others like them, simply refer to other HTML objects. These objects, and their methods and properties, are documented in the chapters that follow.


Previous Home Next
Frame Programming Techniques Book Index The Navigator, Location, and History Objects

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell