Skip to content

Instantly share code, notes, and snippets.

@ethertank
Last active October 12, 2015 20:29
Show Gist options
  • Save ethertank/4082834 to your computer and use it in GitHub Desktop.
Save ethertank/4082834 to your computer and use it in GitHub Desktop.
navigator
(function() {
var bdd = document.createElement("div");
bdd.innerHTML = '<!--[if IE]><q /><![endif]--><!--[if IE 6]><i /><![endif]--><!--[if IE 7]><b /><![endif]--><!--[if IE 8]><s /><![endif]--><!--[if IE 9]><p /><![endif]-->';
navigator.isMSIE = (bdd.getElementsByTagName('q').length) ? true : false;
navigator.isMSIE6 = (bdd.getElementsByTagName('i').length) ? true : false;
navigator.isMSIE7 = (bdd.getElementsByTagName('b').length) ? true : false;
navigator.isMSIE8 = (bdd.getElementsByTagName('s').length) ? true : false;
navigator.isMSIE9 = (bdd.getElementsByTagName('p').length) ? true : false;
// todo
// navigator.isOpera = Object.prototype.toString.call(window.opera) == "[object Opera]"; //dead
navigator.isOpera = String(navigator.vendor).match(/opera/gi)? "maybe" : false;
})();
document.write(
"navigator.isMSIE : " + navigator.isMSIE + "<br />" +
"navigator.isMSIE6 : " + navigator.isMSIE6 + "<br />" +
"navigator.isMSIE7 : " + navigator.isMSIE7 + "<br />" +
"navigator.isMSIE8 : " + navigator.isMSIE8 + "<br />" +
"navigator.isMSIE9 : " + navigator.isMSIE9 + "<br />"​ +
"navigator.isOpera : " + navigator.isOpera + "<br />"
);​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment