Sponsor: The CSS Anthology
The CSS Anthology: 101 Essential Tips, Tricks & Hacks (external link)
Blog Entry
Checking the Browser
Published on the 15th of July 2005
JavaScript can be useful in some hard spots, and a browser detecting script can be very convenient. Detecting the browser of the visitor can easily assist in cross browser web design. JavaScript allows you to access the user's browser via the navigator object:
JavaScript
<script type="text/javascript">
var browser = navigator.appName;
alert(browser);
</script>
You can also use another property of the navigator object known as userAgent to access a description of the browser version of the appName property. Here we can combine the two to make a cleaner alert message:
JavaScript
<script type="text/javascript">
var browser = navigator.appName;
var description = navigator.userAgent;
alert(browser + “/n” + description);
</script>
Some web browsers lack the navigator object, although the latest releases of the major web browsers support it. So when your stuck between a rock and a hard spot, just think JavaScript!
Comments
-
Frank0051 (external link) (24 Jul 2005 17:44)
Well if you are already writing in a scripting language, like PHP, you can use the built in features.
-
Ethan Poole (external link) (25 Jul 2005 16:48)
PHP has no ability to determine what the browser is, or at least as far as I know.
-
Frans (external link) (26 Jul 2005 7:15)
And if it did, it would most likely be old-fashioned the day after... :P
You can use the user agent string sent, of course..
Sponsor: Songbird Media Player
Desktop web player, a digital jukebox, and web browser mash-up. (external link)

