Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JavaScript: How to use JavaScript to determine the type of browser?

DZone's Guide to

JavaScript: How to use JavaScript to determine the type of browser?

· Web Dev Zone ·
Free Resource

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

In order to make Web Applications work in a variety of browsers and take advantage of their unique features, you must first determine the browser.  Depending on the browser, we need to adjust the code, especially the JavaScript code. Before doing this, can use JavaScript to determine the type of browser being used. Here is an example of two functions that determine if a user's browser is IE or Firefox:

function isIE() {
 var ie = (navigator.userAgent.indexOf("MSIE") != -1);
 
 return ie;
}

function isFireFox() {
 var fireFox = (navigator.userAgent.indexOf("Mozilla") != -1 ||
  navigator.userAgent.indexOf("FireFox") != -1);
 
 return fireFox;
}

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}