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.

moveBy(deltaX,deltaY)<br />

moveTo(x,y)<br />

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

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

Compatibility ✓ ✓ ✓ ✓ ✓<br />

Example<br />

Several examples of using the window.moveTo() and window.moveBy() methods<br />

are shown in Listing 16-24. The page presents four buttons, each of which performs<br />

a different kind of browser window movement.<br />

Listing 16-24: Window Boogie<br />

<br />

<br />

Window Gymnastics<br />

<br />

var isNav4 = ((navigator.appName == “Netscape”) &&<br />

(parseInt(navigator.appVersion) >= 4))<br />

// wait in onLoad for page to load and settle in IE<br />

function init() {<br />

// fill missing IE properties<br />

if (!window.outerWidth) {<br />

window.outerWidth = document.body.clientWidth<br />

window.outerHeight = document.body.clientHeight + 30<br />

}<br />

// fill missing IE4 properties<br />

if (!screen.availWidth) {<br />

screen.availWidth = 640<br />

screen.availHeight = 480<br />

}<br />

}<br />

// function to run when window captures a click event<br />

function moveOffScreen() {<br />

// branch for NN security<br />

if (isNav4) {<br />

netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserWrite”)<br />

}<br />

var maxX = screen.width<br />

var maxY = screen.height<br />

window.moveTo(maxX+1, maxY+1)<br />

setTimeout(“window.moveTo(0,0)”,500)<br />

if (isNav4) {<br />

netscape.security.PrivilegeManager.disablePrivilege(“UniversalBrowserWrite”)<br />

}<br />

Continued<br />

161<br />

windowObject.moveBy()

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

Saved successfully!

Ooh no, something went wrong!