码迷,mamicode.com
首页 > 其他好文 > 详细

判断用户使用的终端类型

时间:2017-06-28 23:06:59      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:res   火狐   对象   ase   uc浏览器   htm   lamp   mac os   cti   

切入正题前,的先说一下

Navigator 对象

Navigator 对象包含有关浏览器的信息。

技术分享注意: 没有应用于 navigator 对象的公开标准,不过所有浏览器都支持该对象。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<div id="example"></div>
<script>
    //判断访问终端
    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.*/), //是否为移动终端
                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 , //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf(iPad) > -1, //是否iPad
                webApp: u.indexOf(Safari) == -1, //是否web应该程序,没有头部与底部
                weixin: u.indexOf(MicroMessenger) > -1, //是否微信
                qq: u.match(/\sQQ/i) == " qq" //是否QQ
            };
        }(),
        language:(navigator.browserLanguage || navigator.language).toLowerCase()
    }
    txt = "<p>浏览器代号: " + navigator.appCodeName + "</p>";
    txt+= "<p>浏览器名称: " + navigator.appName + "</p>";
    txt+= "<p>浏览器版本: " + navigator.appVersion + "</p>";
    txt+= "<p>启用Cookies: " + navigator.cookieEnabled + "</p>";
    txt+= "<p>硬件平台: " + navigator.platform + "</p>";
    txt+= "<p>用户代理: " + navigator.userAgent + "</p>";
    txt+= "<p>用户代理语言: " + navigator.systemLanguage + "</p>";
    document.getElementById("example").innerHTML=txt;
    //判断是否IE内核
    if(browser.versions.trident){ alert("is IE"); }
    //判断是否webKit内核
    if(browser.versions.webKit){ alert("is webKit"); }
    //判断是否移动端
    if(browser.versions.mobile||browser.versions.android||browser.versions.ios){ alert("移动端"); }

    //判断如果是手机访问就跳到对应网址
    if (browser.versions.mobile) {

        location.href = "写入跳转地址";

    }
  //作用同上
    if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
        window.location="https://......";
    }
    else if (browser.versions.android) {
        window.location="http://......";
    }
</script>
</body>
</html>

 

判断用户使用的终端类型

标签:res   火狐   对象   ase   uc浏览器   htm   lamp   mac os   cti   

原文地址:http://www.cnblogs.com/iriliguo/p/7091665.html

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