Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Misc | Q43 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.