|
Departments Info Home Page Articles Software GoodiesExplanations How do they do that? The Web in FocusResources Web Site Stuff Tech Books E-Books Tech Toys Web Hosting LinksWomen Opinion Tech Women Women's StudiesTech News Computer Security Databases Java Linux MP3 PC Software Robotics Site Owner Tech Latest Web Development XMLSpread the Word Newsletter
Recommend this Page
Site Info Legal Disclaimer
Privacy
Contact
Lighter Side Crazy for Life crazy for romance Crazy for Kitties Crazy for Dogs Crazy for CowsCopyright 2000-2001, hertechnology.com |
Your Second Program The second program The program goes in an HTML file inside special <SCRIPT> tags. Create a file and either type or copy what you see on the screen into your file. You can name the file anything you like. My version is called focus3.html.
<html> I put the else term on its own line so it is easier to read. If you do type this in, be sure to type in the JavaScript exactly as you see it -- upper and lower case letters especially. HTML can be typed in upper or lower case, but JavaScript can't. Note that navigator.appName has a capital N in Name. Try it. You may want to bring up your other browser and try it again to see if you get a different message. (You might not, as you'll see next.) There is a flaw in this program that I'll fix at a later time by using a JavaScript function called indexOf. I'll talk about functions and show using indexOf to make this little program more robust. The flaw is this. If the name of the browser as given by navigator.appName is something like "Netscape Navigator", the if test will give a false and the stuff you do when the if test is false will be done -- namely, the words "Hey IE user!" will be printed to the screen. This result is clearly wrong. The problem is that the if test expects the name of the browser to be exactly the word "Netscape" (without the double quotes). Even if the name is given as "netscape" with a lowercase n, the test will be false. While checking for the word "Netscape" exactly works fine on my PC running Windows NT, doing the test like that is not guaranteed to work all the time. A better way would be to see if the word "Netscape" appeared anywhere in the name. That is what indexOf will do. (indexOf won't take care of the upper/lower case situation, but that can be taken care of, too, in another way.) Another problem is that if you are running a browser other than Netscape or Internet Explorer, the program will say "Hey IE user!". This situation can be fixed by adding another test. I'll leave these improvements for next time. So, now you've gotten through another program. Stay tuned for more! Written June 30, 2000 |
|