Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
デバイスやブラウザを判定する Modernizr 用の追加テストです。 えっと…。いや、実務では要りますよ。やっぱり。今回まとめました。
(function() {
if (!window.Modernizr) {
return;
}
var ua = new String(window.navigator.userAgent.toLowerCase());
ua.has = function (cond) {
return this.indexOf(cond) != -1;
};
var msie = ua.has('msie');
var chrome = ua.has('chrome');
var safari = ua.has('safari') && chrome;
var firefox = ua.has('firefox');
var opera = ua.has('opera') || ua.has('opr/'); //opera 15+
Modernizr.addTest({
'msie' : function () { return msie; },
'chrome' : function () { return chrome; },
'safari' : function () { return safari; },
'firefox' : function () { return firefox; },
'opera' : function () { return opera; }
});
var iphone = ua.has('iphone');
var ipod = ua.has('ipod');
var ipad = ua.has('ipad');
var macosx = ua.has('mac os x');
var android = ua.has('android');
var androidPhone = android && ua.has('mobile');
var androidTablet = android && ! ua.has('mobile');
var windows = ua.has('windows');
var windowsPhone = windows && ua.has('phone');
var windowsTablet = windows && ua.has('touch');
Modernizr.addTest({
'ios' : function () { return iphone || ipod || ipad; },
'iphone' : function () { return iphone; },
'ipod' : function () { return ipod; },
'ipad' : function () { return ipad; },
'macosx' : function () { return macosx; },
'android' : function () { return android; },
'androidPhone' : function () { return androidPhone; },
'androidTablet' : function () { return androidTablet; },
'windows' : function () { return windows; },
'windowsPhone' : function () { return windowsPhone; },
'windowsTablet' : function () { return windowsTablet; },
});
}());
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.