JavaScript

如何判断是否是手机浏览器访问

$.extend({
    isMobile : function(){
        var userAgent = navigator.userAgent.toLowerCase();
        var isIpad = userAgent.match(/ipad/i) == "ipad";
        var isIphone = userAgent.match(/iphone/i) == "iphone";
        var isIphoneOs = userAgent.match(/iphone os/i) == "iphone os";
        var isMidp = userAgent.match(/midp/i) == "midp";
        var isUc7 = userAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
        var isUcWeb = userAgent.match(/ucweb/i) == "ucweb";
        var isAndroid = userAgent.match(/android/i) == "android";
        var isWCE = userAgent.match(/windows ce/i) == "windows ce";
        var isWM = userAgent.match(/windows mobile/i) == "windows mobile";
        if (isIpad || isIphone || isIphoneOs || isMidp || isUc7 || isUcWeb || isAndroid || isWCE || isWM) {
            return true;
        } else {
            return false;
        }
    }
});
alert($.isMobile());


文章推荐:

https://www.jb51.net/article/73405.htm

https://www.jb51.net/article/44375.htm




转载请指明出处!http://www.miselehe.com/article/view/96