1 //JS判断当前设备类型 2 var os = function (){ 3 var ua = navigator.userAgent, 4 isWindowsPhone = /(?:Windows Phone)/.test(ua), 5 isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, 6 isAndroid = /(?:Android)/.test(ua), 7 isFireFox = /(?:Firefox)/.test(ua), 8 isChrome = /(?:Chrome|CriOS)/.test(ua), 9 isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)), 10 isPhone = /(?:iPhone)/.test(ua) && !isTablet, 11 isPc = !isPhone && !isAndroid && !isSymbian; 12 return { 13 isTablet: isTablet, 14 isPhone: isPhone, 15 isAndroid: isAndroid, 16 isPc: isPc 17 }; 18 }(); 19 if (os.isAndroid || os.isPhone) { 20 alert("phone" ); 21 } else if (os.isTablet) { 22 alert("pad" ); 23 } else if (os.isPc) { 24 alert("pc") 25 }