15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2 ✦ Window and Frame Objects (Chapter 16)<br />

To run successfully in NN, the first button requires that you have codebase principals<br />

turned on (see Chapter 46 of the <strong>JavaScript</strong> <strong>Bible</strong>) to take advantage of what<br />

would normally be a signed script. The moveOffScreen() function momentarily<br />

moves the window entirely out of view. Notice how the script determines the size of<br />

the screen before deciding where to move the window. After the journey off screen,<br />

the window comes back into view at the upper-left corner of the screen.<br />

If using the Web sometimes seems like going around in circles, then the second<br />

function, revolve(), should feel just right. After reducing the size of the window<br />

and positioning it near the top center of the screen, the script uses a bit of math to<br />

position the window along 36 places around a perfect circle (at 10-degree increments).<br />

This is an example of how to control a window’s position dynamically<br />

based on math calculations. IE complicates the job a bit by not providing properties<br />

that reveal the outside dimensions of the browser window.<br />

To demonstrate the moveBy() method, the third function, zigzag(), uses a for<br />

loop to increment the coordinate points to make the window travel in a saw tooth<br />

pattern across the screen. The x coordinate continues to increment linearly until<br />

the window is at the edge of the screen (also calculated on the fly to accommodate<br />

any size monitor). The y coordinate must increase and decrease as that parameter<br />

changes direction at various times across the screen.<br />

In the fourth function, you see some practical code (finally) that demonstrates<br />

how best to simulate maximizing the browser window to fill the entire available<br />

screen space on the visitor’s monitor.<br />

navigate(“URL”)<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓<br />

Example<br />

Supply any valid URL as the parameter to the method, as in<br />

window.navigate(“http://www.dannyg.com”)<br />

open(“URL”, “windowName” [,<br />

“windowFeatures”][,replaceFlag])<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

The page rendered by Listing 16-26 displays a single button that generates a new<br />

window of a specific size that has only the statusbar turned on. The script here<br />

163<br />

windowObject.open()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!