user agent cheker
by uto usui
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
<h1 class="h1 font-weight-bold text-xs-center text-capitalize">user agent cheker</h1>
<div class="wrap">
<div class="inner">
<div class="ex" id="ex"></div>
</div>
</div>
SCSS
body {
width: 100%;
min-height: 100vh;
padding-bottom: 150px;
background-image: linear-gradient(45deg, #F7CAC9 15%, #91A8D0 85%);
}
.h1 {
margin: 2em;
font-family: 'Dancing Script', cursive;
color: rgba(white, .85);
}
.wrap {
display: flex;
justify-content: center;
align-items: center;
}
.inner {
display: block;
transform-style: preserve-3d;
perspective: 800px;
}
.ex {
font-size: 40px;
font-family: 'Dancing Script', cursive;
background-color: rgba(#fafafa,.45);
}
JavaScript
function uaCheck () {
// tab or sp or ie
var ua = (function (u) {
return {
//
sp: (u.indexOf("windows") != -1 && u.indexOf("phone") != -1) || u.indexOf("iphone") != -1 || u.indexOf("ipod") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") != -1) || (u.indexOf("firefox") != -1 && u.indexOf("mobile") != -1) || u.indexOf("blackberry") != -1,
//
tab: u.indexOf("ipad") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") == -1) || (u.indexOf("firefox") != -1 && u.indexOf("tablet") != -1) || u.indexOf("kindle") != -1 || u.indexOf("silk") != -1 || u.indexOf("playbook") != -1,
//
ie: u.indexOf('msie') != -1 || u.indexOf('trident') != -1
}
})(window.navigator.userAgent.toLowerCase());
// numbering
var num;
if (ua.sp) {
// sp
num = 3;
} else if (ua.tab) {
// tab
num = 2;
} else if (ua.ie) {
// IE
num = 1;
} else {
// other
num = 0;
}
if (num == 3) {
$('#ex').text('sp');
} else if (num == 2) {
$('#ex').text('pad');
} else if (num == 1) {
$('#ex').text('IE');
} else {
$('#ex').text('PC, not IE');
}
}
uaCheck ();
WebFontConfig = {
google: { families: [ 'Dancing+Script:400,700:latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();