码迷,mamicode.com
首页 > Web开发 > 详细

JS判断浏览器类型,JS判断客户端操作系统

时间:2015-08-20 12:31:15      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

JS判断浏览器类型

function judge(){    
    var browser = {
        versions: function() {
                var u = navigator.userAgent, app = navigator.appVersion;
                return {//移动终端浏览器版本信息
                    trident: u.indexOf(Trident) > -1, //IE内核
                    presto: u.indexOf(Presto) > -1, //opera内核
                    webKit: u.indexOf(AppleWebKit) > -1, //苹果、谷歌内核
                    gecko: u.indexOf(Gecko) > -1 && u.indexOf(KHTML) == -1, //火狐内核
                    mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
                    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                    android: u.indexOf(Android) > -1 || u.indexOf(Linux) > -1, //android终端或者uc浏览器
                    iPhone: u.indexOf(iPhone) > -1 || u.indexOf(Mac) > -1, //是否为iPhone或者QQHD浏览器
                    iPad: u.indexOf(iPad) > -1, //是否iPad
                    webApp: u.indexOf(Safari) == -1 //是否web应该程序,没有头部与底部
                };
             }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }
    console.log(browser.language)
    if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
        // window.location="www.zhongsou.com";
    }else if (browser.versions.android) {
        // window.location="http://www.baidu.com";
    }
    /*window.location.href="https://itunes.apple.com/us/app/ma-ma-fan-er/id985525130?mt=8&uo=4";*/
}
var bb=new judge();

JS判断客户端操作系统

function detectOS() {
    var sUserAgent = navigator.userAgent;
    var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
    var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
    if (isMac) return "Mac";
    var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
    if (isUnix) return "Unix";
    var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
    if (isLinux) return "Linux";
    if (isWin) {
        var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
        if (isWin2K) return "Win2000";
        var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
        if (isWinXP) return "WinXP";
        var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
        if (isWin2003) return "Win2003";
        var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
        if (isWinVista) return "WinVista";
        var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
        if (isWin7) return "Win7";
    }
    return "other";
}
 
document.writeln("您的操作系统是:" + detectOS());

 

JS判断浏览器类型,JS判断客户端操作系统

标签:

原文地址:http://www.cnblogs.com/makan/p/4744552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!