Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q43 How do I detect the browser the user is using?

You are here: irt.org | FAQ | JavaScript | Misc | Q43 [ previous next ]

Try something like the following:

<script language="JavaScript"><!--
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);
document.write('Your browser is: ' + navigator.appName + ' ' + version + '<br>');
//--></script>

This is rather simplistic, for The Ultimate JavaScript Client Sniffer please refer to Netscape site at http://developer.netscape.com/library/examples/javascript/browser_type.html which gives you more than enough information about detecting the browser.

Personally I've never felt the need to know so much information about a browser. What is important is to know whether the browser will support some feature that you are trying to utilise, for instance images for image highlighting.

The well established method is to check as follows:

if (document.images) {
     // insert image swapping code
}

Other techniques: Checking for Netscape 4 and Explorer 4, which support Layers and DHTML respectively:

if (document.layers) {
}
else if (document.all) {
}

Feedback on 'Q43 How do I detect the browser the user is using?'

©2018 Martin Webb