Transcript Chapter 4

The Web Wizard’s Guide To
DHTML and CSS
Chapter 4
Building Your Dynamic HTML
Code Library
Chapter Objectives
• To start creating a library of reusable code
• To include browser detection in a library
• To create library functions for 3-D positioning
• To learn about library functions used for window
size manipulation
Beginning Your Code Library
• What’s an API?
• A toolbox full of code
• Store in a simple text file
Browser Detection Code
• Tool number 1 in your code library.
• Detect browsers by feature support
• var theDOM1 = (document.getElementById) ? true : false;
• Detect browsers by name
• var UA = navigator.userAgent.toLowerCase();
• Detect the platform in use
• var isMAC = (UA.indexOf('mac') >= 0) ?
true : false;
• var isWIN = (UA.indexOf('win') >= 0) ?
true : false;
Using Object-Positioning
Library Code
•
•
•
•
Create a getObj() function
Create a shiftTo() function
Create functions to find x, y, and z
Create a function to empty a node
•
•
•
•
Library Code to Change
Window Size
A function to get the available width
A function to get the available height
A function to set the window size
A function to maximize the window