function checkBrowser() {
// Get the user-agent string
let userAgentString =
navigator.userAgent;
// Detect Chrome
let chromeAgent =
userAgentString.indexOf("Chrome") > -1;
// Detect Internet Explorer
let IExplorerAgent =
userAgentString.indexOf("MSIE") > -1 ||
userAgentString.indexOf("rv:") > -1;
// Detect Firefox
let firefoxAgent =
userAgentString.indexOf("Firefox") > -1;
// Detect Safari
let safariAgent =
userAgentString.indexOf("Safari") > -1;
// Discard Safari since it also matches Chrome
if ((chromeAgent) && (safariAgent))
safariAgent = false;
// Detect Opera
let operaAgent =
userAgentString.indexOf("OP") > -1;
// Discard Chrome since it also matches Opera
if ((chromeAgent) && (operaAgent))
chromeAgent = false;
console.log(safariAgent);
console.log(chromeAgent);
console.log(IExplorerAgent);
console.log(operaAgent);
console.log(firefoxAgent);
}
checkBrowser();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.