//from http://css-tricks.com/snippets/jquery/display-browser-and-version/
var userAgent = navigator.userAgent.toLowerCase(),
browser = '',
version = 0;
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
// Is this a version of IE?
if ($.browser.msie) {
userAgent = $.browser.version;
userAgent = userAgent.substring(0,userAgent.indexOf('.'));
version = userAgent;
browser = "Internet Explorer";
}
// Is this a version of Chrome?
if ($.browser.chrome) {
userAgent = userAgent.substring(userAgent.indexOf('chrome/') + 7);
userAgent = userAgent.substring(0,userAgent.indexOf('.'));
version = userAgent;
// If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
$.browser.safari = false;
browser = "Chrome";
}
// Is this a version of Safari?
if ($.browser.safari) {
userAgent = userAgent.substring(userAgent.indexOf('safari/') + 7);
userAgent = userAgent.substring(0,userAgent.indexOf('.'));
version = userAgent;
browser = "Safari";
}
// Is this a version of Mozilla?
if ($.browser.mozilla) {
//Is it Firefox?
if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
userAgent = userAgent.substring(userAgent.indexOf('firefox/') + 8);
userAgent = userAgent.substring(0,userAgent.indexOf('.'));
version = userAgent;
browser = "Firefox"
}
// If not then it must be another Mozilla
else {
browser = "Mozilla (not Firefox)"
}
}
// Is this a version of Opera?
if ($.browser.opera) {
userAgent = userAgent.substring(userAgent.indexOf('version/') + 8);
userAgent = userAgent.substring(0,userAgent.indexOf('.'));
version = userAgent;
browser = "Opera";
}
// Now you have two variables, browser and version
// which have the right info
$('#output').text(browser+' '+version);
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.