Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Browser support- alternative to modernizr
// Browser support
(function (d, h, w, n) {
//function hasProperties(properties, tagName) {
// var isStyle = !!!tagName;
// tagName = tagName || 'div';
// var el = d.createElement(tagName);
// for (var prop in properties) {
// if ((isStyle ? el.style[properties[prop]] : el[properties[prop]]) !== undefined ) {
// return true;
// }
// }
// return false;
//}
var tests = {
'touch' : ('ontouchstart' in w) || w.DocumentTouch && d instanceof DocumentTouch
// 'formvalidation' : hasProperties(['checkValidity'],'form'),
// 'pushState' : !!history.pushState,
},
htmlClasses = h.className,
ua = n.userAgent;
w.supports = tests;
htmlClasses = htmlClasses.replace('no-js','js');
for (var i in tests) {
htmlClasses += (tests[i] ? ' ' : ' no-') + i;
}
IE = false;
var browserString = ua.match(/edge/i)
? 'edge'
: ua.match(/Trident|firefox|chrome|safari/i)[0];
if (browserString === 'Trident') {
var version = ua.indexOf('rv: 11.0') > 0 || ua.indexOf('rv:11.0') > 0
? 11
: ua.substr(ua.indexOf('MSIE')+ 5,2).replace('.','');
h.className += ' ie ie' + version;
IE = parseInt(version, 10);
} else {
h.className+=' ' + browserString.toLowerCase();
w[browserString.toUpperCase()] = true;
}
h.setAttribute('ua', n.userAgent);
h.setAttribute('os', n.platform);
})(document,document.documentElement,window,navigator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.