Dan Barrett Dan Livingston Micah Brown Publisher: Prentice Hall PTR First Edition August 03, 1999 ISBN: 0-13-013056-7, 224 pages
How This Book Is Laid Out
This is often how we expand our skills: We are given a job, and if we don't know exactly how to do it, we quickly learn how. In keeping with this real-world model, this book is split into two main projects. For each of the main projects, we will be responsible for creating and/or upgrading the Web site for a fictitious company.
For all of the examples in the book you can go to the companion Web site located at http://www.phptr.com/essential and download the HTML and images needed to follow along with the exercises.
Browsers and Versions
As stated earlier, IE and Navigator differ slightly in the implementation of their scripting languages. As a programmer, this makes your life a little more difficult: There will be times when a solution will work differently or not at all on different browsers. Waitit gets worse: As Netscape and Microsoft come out with newer versions of their browsers, the versions of their scripting languages are changing as well. This means that scripts written using new features may not work in an older browser. But don't get too upsetit's not as bad as it seems. All this means is that you will have to take a little extra care in writing and checking your scripts.
A security feature called the Same Origin Policy also restricts the access of scripts from one origin access to certain properties or files from other locations. For example, if you have a script located at http://www.yoursite.com/test.html and it tries to access certain properties of an HTML page located at http://www.theirsite.com/test.html], the Same Origin Policy will deny your script access. The properties that the Same Origin Policy restricts are shown in Figure I-1.
Figure I-1. Same Origin Policy restrictions
As you are starting out, if you think of a possible solution that may differ from the examples in the book, give it a shot; you can often stumble upon a solution that others may not have thought of. With all that said, let's get on with the learning.
Chapter 1. Dynamism and Detection
In This Chapter
Project I: Generating Platform-Specific Content Project II: Printing Copyright Information and Last-Modified Date Recap
Figure 1.1. Font differences on the different platforms
Project I: Generating Platform-Specific Content
After playing around with the existing HTML, you have concluded that, in order for the page to look the same on both platforms, a font size of 2 for the Macintosh and a font size of 3 for Windows machines are required. To solve our problem we are going to need to write the FONT tag dynamically into the HTML, so our script needs to be placed inside the body of the HTML in the spot where the FONT tag would normally reside.
For this first script there are two main parts: First, we must find out what platform the user is on; and second, we need to have the browser dynamically print out the different code needed for each.
Inserting a Script into Your HTML
There are several other ways in which you can embed your scripts into your HTML: