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

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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;
}

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}