WordPress Code Snippets

A fresh mix of code snippets and tutorials

Detect Chrome, IE, Firefox, Opera, and Safari


How to detect each of the major browsers (Chrome, IE, Firefox, Opera, Safari) client-side via JavaScript.


Note that this technique employs user-agent sniffing via JavaScript. User-agent sniffing is not as reliable as feature detection, so make sure to read up and make the best decision before using this technique.

Detect major browsers with JavaScript

Here is a JavaScript snippet to detect each of the major browsers, Chrome, IE, Firefox, Opera, and Safari.

That provides a set of variables that we can use to conditionally check for specific browsers and apply any desired code, for example:

if (explorer) alert('Internet Explorer');

Repeat: use this technique with caution, browsers are constantly changing their reported user agents for no apparent reason whatsoever. Even so, browser detection remains a useful technique for those one-off cases where including an entire feature-detection library would be overkill.

Show Support

Like our new Facebook Page to show support!