热门关键字:
jquery > jquery教程 > javascript > 原生javascript检测是否移动设备访问包括了45种

原生javascript检测是否移动设备访问包括了45种

1051
作者:管理员
发布时间:2015/4/28 14:00:18
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=540

功能:原生javascript检测是否移动设备访问包括了45种


代码如下:

function checkMobile() {
    var pda_user_agent_list = new Array("2.0 MMP", "240320", "AvantGo", "BlackBerry", "Blazer", "Cellphone", "Danger", "DoCoMo", "Elaine/3.0", "EudoraWeb", "hiptop", "IEMobile", "KYOCERA/WX310K", "LG/U990", "MIDP-2.0", "MMEF20", "MOT-V", "NetFront", "Newt", "Nintendo Wii", "Nitro", "Nokia", "Opera Mini", "Opera Mobi", "Palm", "Playstation Portable", "portalmmm", "Proxinet", "ProxiNet", "SHARP-TQ-GX10", "Small", "SonyEricsson", "Symbian OS", "SymbianOS", "TS21i-10", "UP.Browser", "UP.Link", "Windows CE", "WinWAP", "Androi", "iPhone", "iPod", "iPad", "Windows Phone", "HTC");
    var pda_app_name_list = new Array("Microsoft Pocket Internet Explorer");

    var user_agent = navigator.userAgent.toString();
    for (var i = 0; i < pda_user_agent_list.length; i++) {
        if (user_agent.indexOf(pda_user_agent_list[i]) >= 0) {
            return true;
        }
    }
    var appName = navigator.appName.toString();
    for (var i = 0; i < pda_app_name_list.length; i++) {
        if (user_agent.indexOf(pda_app_name_list[i]) >= 0) {
            return true;
        }
    }

    return false;
}

if (checkMobile()) {
    location.href = ""; //移动端域名
}





如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:javascript 移动设备 android ios
友荐云推荐