Skip to content

Instantly share code, notes, and snippets.

@ixzy24
Created June 3, 2012 13:30
Show Gist options
  • Save ixzy24/2863506 to your computer and use it in GitHub Desktop.
Save ixzy24/2863506 to your computer and use it in GitHub Desktop.
JavaScript browser detection
// Browser detection
// Internet Explorer
var ie = document.all != null; //ie4 and above
var ie5 = document.getElementById && document.all;
var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0);
// Netscape
var ns4 = document.layers != null;
var ns6 = document.getElementById && !document.all;
var ns = ns4 || ns6;
// Firefox
var ff = !document.layers && !document.all;
// Opera
var op = navigator.userAgent.indexOf("opera")>0;
var op7 = op && operaVersion() <= 7;
var op8 = op && operaVersion() >= 8;
// Detects the Opera version
function operaVersion() {
agent = navigator.userAgent;
idx = agent.indexOf("opera");
if (idx>-1) {
return parseInt(agent.subString(idx+6,idx+7));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment