Modern JavaScript: Develop and Design (Richard Stout's Library) by Larry Ullman

Modern JavaScript: Develop and Design (Richard Stout's Library) by Larry Ullman

Author:Larry Ullman
Language: eng
Format: mobi
Publisher: Peachpit Press
Published: 2012-01-17T23:00:00+00:00


Figure 9.7. How windows are positioned relative to the entire screen.

The innerHeight and innerWidth properties reflect the size of the content within the window, including scroll bars, when present. The outerHeight and outerWidth properties reflect the size of the entire browser window (see Figure 9.6). For older versions of IE, which only started supporting these properties in version 9, you need to use document.body.clientHeight and document.body.clientWidth. You cannot change the size of the window using any of these properties (except in Firefox), but they can be used as the basis for dynamically changing your layout, if need be. For example, if a window dimension is particularly small, you could have JavaScript use smaller images. If a window’s width is narrow, perhaps JavaScript disables a sidebar.

If, for some very, very, very good reason you need to move the browser window, you would call the moveTo() method of the window object. It takes X and Y pixel values for its arguments, where 0,0 is the top-left corner of the screen (see Figure 9.7). The following code moves the window to place its top-left corner positioned 100 pixels to the right of the left side of the screen and 200 pixels down from the top of the screen:

window.moveTo(100,200);

Whereas moveTo() moves the window to a specific location, moveBy() moves a window relative to its current location. It, too, takes X and Y values, in terms of the number of pixels to move the window:

window.moveBy(25, 50);

Positive numbers move the window to the right and down; negative numbers move the window up and to the left. That code moves the window 25 pixels to the right and 50 pixels down from its current location. Note that you will not be allowed to move the window beyond the confines of the screen.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.