Detect Test

HTML
test
CSS
JAVASCRIPT
var detect = { Android: function () { return navigator.userAgent.match(/Android/i); }, BlackBerry: function () { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function () { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function () { return navigator.userAgent.match(/Opera Mini/i); }, Safari: function () { if (window.safari !== undefined) { return "safari"; } }, Windows: function () { return navigator.userAgent.match(/IEMobile/i); }, ie: function () { var isIE_Check = false; // Internet Explorer 6-11 var isIE = /*@cc_on!@*/false || !!document.documentMode; if (isIE) { isIE_Check = true } // Edge 20+ //var isEdge = !isIE && !!window.StyleMedia; var isEdge =document.documentMode || /Edge/.test(navigator.userAgent) || /Edg/.test(navigator.userAgent) if (isEdge) { isIE_Check = true } return isIE_Check }, ie11: function () { var isIE_Check = false; // Internet Explorer 6-11 //var isIE = /*@cc_on!@*/false || !!document.documentMode; var isIE = !!window.MSInputMethodContext && !!document.documentMode; if (isIE) { isIE_Check = true } return isIE_Check }, anyMobile: function () { return (detect.Android() || detect.BlackBerry() || detect.iOS() || detect.Opera() || detect.Windows()); } }; //If Mobile if (detect.anyMobile()) { console.log("detectMobile") document.body.classList.add("detectMobile"); } //Non mobile browser if (!detect.anyMobile()) { //For IE if (detect.ie()) { console.log("detectIE") document.body.classList.add("detectIE"); } //For IE11 if (detect.ie11()) { console.log("detect IE11") document.body.classList.add("detectIE11"); } //For Safari if (detect.Safari()) { console.log("detectSafari") document.body.classList.add("detectSafari"); } } console.log(document.getElementsByTagName("BODY")[0])
Expand for more options Login