Last active
August 29, 2015 14:14
-
-
Save mreis1/18433c6f7c82511b837f to your computer and use it in GitHub Desktop.
Javascript check user agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VIEWPORT SETTINGS | |
/* | |
if (navigator.userAgent.indexOf('iPhone') != -1) { | |
document.write('<meta name="viewport" content="width=480px, maximum-scale=1.0, user-scalable=0">'); | |
} | |
if (navigator.userAgent.indexOf('iPad') != -1) { | |
document.write('<meta name="viewport" content="width=1024px, maximum-scale=1.0, user-scalable=0">'); | |
} | |
if (navigator.userAgent.indexOf('Android') != -1) { | |
}*/ | |
var deviceSettings = { | |
isAndroid: null, | |
isEarlyIE: null, | |
isIE: null, | |
isiPod: null, | |
isiPhone: null, | |
isiPad: null, | |
isiOS: null, | |
isMobile: null, | |
isTablet: null, | |
isWinSafari: null, | |
isMacSafari: null | |
}, | |
startPos, | |
endPos, | |
inTransition = false; | |
function setupDeviceSettings() { | |
var ua = navigator.userAgent.toLowerCase(); | |
deviceSettings.isAndroid = ua.indexOf("android") > -1; | |
deviceSettings.isEarlyIE = (jQuery.browser.msie == true && Number(jQuery.browser.version) <= 8) ? true : false; | |
deviceSettings.isIE = jQuery.browser.msie == true; | |
deviceSettings.isiPod = navigator.userAgent.match(/iPod/i) != null; | |
deviceSettings.isiPhone = navigator.userAgent.match(/iPhone/i) != null; | |
deviceSettings.isiPad = navigator.userAgent.match(/iPad/i) != null; | |
deviceSettings.isiOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false); | |
//determine if this is a mobile browser: | |
var p = navigator.platform.toLowerCase(); | |
if (deviceSettings.isAndroid || deviceSettings.isiPad || p === 'ipad' || p === 'iphone' || p === 'ipod' || p === 'android' || p === 'palm' || p === 'windows phone' || p === 'blackberry' || p === 'linux armv7l') { | |
deviceSettings.isMobile = true; | |
} | |
var safari = ($.browser.webkit && !(/chrome/.test(navigator.userAgent.toLowerCase()))); | |
var windows = (ua.indexOf("windows") !== -1); | |
var mac = (ua.indexOf("mac") !== -1); | |
if (safari && windows) { | |
deviceSettings.isWinSafari = true; | |
} | |
if (safari && mac) { | |
deviceSettings.isMacSafari = true; | |
} | |
/*if (deviceSettings.isAndroid || p === 'iphone' || p === 'ipod' || p === 'android' || p === 'palm' || p === 'windows phone' || p === 'blackberry' || p === 'linux armv7l') { | |
document.write('<meta name="viewport" content="width=480px, maximum-scale=1.0, user-scalable=0">'); | |
} | |
if (deviceSettings.isiPad || p === 'ipad') { | |
document.write('<meta name="viewport" content="width=1024px, maximum-scale=1.0, user-scalable=0">'); | |
}*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment