Browser, Schmouser by Heidi Brumbaugh
I've been thinking a lot about my six-year old lately, who's been having trouble making friends since our recent move. The problem is that she loves having other kids over, as long as they play her games. If they don't she pouts, then agrees to play what they're playing, but then immediately starts in to make her own arbitrary and dictatorial changes to the rules.
To make matters even more confusing, each browser version contains its own "upgrades" to the protocol, giving us a geometric progression of compatibility problems. This article will give you a overview of JScript and discuss some of the more glaring compatibility issues. Then it will give code to check which browser (and version) your user is running. Finally, I'll point to some resources to give you more thorough details on the incompatibilities.
One key difference in the JScript object model is that there is no Area or Image object. Because of this, you can't use JScript directly to change an image on an HTML page. As more than one reader pointed out to me after another article, the onMouseOver example simply won't work in Internet Explorer. Sigh.
Once you're aware of the compatibility problems between the two major browsers, the next step is to manage the problems as gracefully as possible. The most effective technique is to add a statement checking the name and version number of the user's browser, and then execute code only where it's supported.
Browser information is stored in the navigator object. The appName property specifies the name of the browser and appVersion specifies the version. So to execute different code depending on the browser name, you would use an if statement, as in:
if (navigator.appName == "Netscape") document.write("Netscape Navigator rules!! All right!!!") else document.write("Internet Explorer rules!! Way to go!!!")
Run this program to get a closer look at the properties of the navigator object.
Thanks for all the email! This article is a direct result of readers' questions. Write to me at firstname.lastname@example.org, and remember, I need your feedback but I can't guarantee an individual response.
Web Developer® Site Feedback
Copyright © 2000 internet.com Corporation. All rights reserved.