detectors.js,这个js我从github中的一个项目上扒下来的,项目地址:https://github.com/J2MTecnologia/app61bits/tree/af85bcd7fed66634ca2cd8706a1bfcf70a2bf43d
detectors.js:https://github.com/J2MTecnologia/app61bits/blob/af85bcd7fed66634ca2cd8706a1bfcf70a2bf43d/src/chui/detectors.js
代码如下:
(function($) { "use strict"; $.extend({ isiPhone : /iphone/img.test(navigator.userAgent), isiPad : /ipad/img.test(navigator.userAgent), isiPod : /ipod/img.test(navigator.userAgent), isiOS : /ip(hone|od|ad)/img.test(navigator.userAgent), isAndroid : (/android/img.test(navigator.userAgent) && !/trident/img.test(navigator.userAgent)), isWebOS : /webos/img.test(navigator.userAgent), isBlackberry : /blackberry/img.test(navigator.userAgent), isTouchEnabled : ('createTouch' in document), isOnline : navigator.onLine, isStandalone : navigator.standalone, isiOS6 : navigator.userAgent.match(/OS 6/i), isiOS7 : navigator.userAgent.match(/OS 7/i), isWin : /trident/img.test(navigator.userAgent), isWinPhone : (/trident/img.test(navigator.userAgent) && /mobile/img.test(navigator.userAgent)), isIE10 : navigator.userAgent.match(/msie 10/i), isIE11 : navigator.userAgent.match(/msie 11/i), isWebkit : navigator.userAgent.match(/webkit/), isMobile : /mobile/img.test(navigator.userAgent), isDesktop : !(/mobile/img.test(navigator.userAgent)), isSafari : (!/Chrome/img.test(navigator.userAgent) && /Safari/img.test(navigator.userAgent) && !/android/img.test(navigator.userAgent)), isChrome : /Chrome/img.test(navigator.userAgent), isNativeAndroid : (/android/i.test(navigator.userAgent) && /webkit/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent)) }); })(window.$);
ps:以备后用
function escapeHTML(a) { return a.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/ /g, " ").replace(/"/g, """).replace(/'/g, "'") }