作为程序员一定要保持良好的睡眠,才能好编程

js判断访问者来源于什么设备

发布时间:2016-07-07

    $(function () {
            QosSS.c = new Image();
            QosSS.c.onload = (QosSS.c.onerror = function() {delete QosSS.c;});
            QosSS.t[2]= (new Date()).getTime();
            QosSS.c.src="http://qos.report.qq.com/collect?type=1&name="+"www.qq.com"+"&1="+ (QosSS.t[1]- QosSS.t[0])+"&2="+ (QosSS.t[2]- QosSS.t[0]);
            // qq浏览器测速
            var UA = navigator.userAgent.toLowerCase();
            if(UA.indexOf('qqbrowser')>-1) {
                var re = /qqbrowser\/(\d+.\d+)/;;
                var r = re.exec(UA);
                var v = +r[1];
                if(v < 9.2) {
                    v = 'qqbrowserlt9.2';
                }else{
                    v = 'qqbrowser' + v;
                }

                QosSS.d_qb = new Image();
                QosSS.d_qb.onload = (QosSS.d_qb.onerror = function() {delete QosSS.d_qb;});
                QosSS.d_qb.src="http://qos.report.qq.com/collect?type=1&name="+ v +"&1="+ (QosSS.t[1]- QosSS.t[0])+"&2="+ (QosSS.t[2]- QosSS.t[0]);
            // 搜狗
            }else if(/\sse\s/.test(UA)) {
                QosSS.d_sg = new Image();
                QosSS.d_sg.onload = (QosSS.d_sg.onerror = function() {delete QosSS.d_sg;});
                QosSS.d_sg.src="http://qos.report.qq.com/collect?type=1&name="+ "sougou" +"&1="+ (QosSS.t[1]- QosSS.t[0])+"&2="+ (QosSS.t[2]- QosSS.t[0]);
            // 猎豹
            }else if(/lbbrowser/.test(UA)) {
                QosSS.d_lb = new Image();
                QosSS.d_lb.onload = (QosSS.d_lb.onerror = function() {delete QosSS.d_lb;});
                QosSS.d_lb.src="http://qos.report.qq.com/collect?type=1&name="+ "liebao" +"&1="+ (QosSS.t[1]- QosSS.t[0])+"&2="+ (QosSS.t[2]- QosSS.t[0]);
            // UC
            }else if(/ubrowser/.test(UA)) {
                QosSS.d_uc = new Image();
                QosSS.d_uc.onload = (QosSS.d_uc.onerror = function() {delete QosSS.d_uc;});
                QosSS.d_uc.src="http://qos.report.qq.com/collect?type=1&name="+ "uc" +"&1="+ (QosSS.t[1]- QosSS.t[0])+"&2="+ (QosSS.t[2]- QosSS.t[0]);
            }
        });    
        
        
        
 //平台检测
function platformCheck(){
    if(navigator.platform == "Mac68K" || navigator.platform == "MacPPC" || navigator.platform == "Macintosh" || navigator.platform == "MacIntel"){ //mac系统
        $("#select").addClass("macSelect");
    }
}
//字体适配
function fontCheck(){
    if(navigator.platform == "Win32" || navigator.platform == "Windows"){ //windows系统
        if($("#guess").width() != 86){ //没有微软雅黑字体
            $("body").addClass("noYahei");
        }
    }
    if(navigator.platform == "Mac68K" || navigator.platform == "MacPPC" || navigator.platform == "Macintosh" || navigator.platform == "MacIntel"){ //mac系统
        $("body").addClass("mac");
    }
}


//判断浏览器是什么类型
if(window.location.toString().indexOf('pref=padindex') != -1){
}else{
    if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){  
      if(window.location.href.indexOf("?mobile")<0){
        try{
            if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
                window.location.href="http://xw.qq.com/index.htm";
            }else if(/iPad/i.test(navigator.userAgent)){
                  window.location.href="http://www.qq.com/pad/"
            }else{
                window.location.href="http://xw.qq.com/simple/s/index/"
            }
        }catch(e){}
    }
    }
}


/*返回顶部*/
function toTopHide(){
    if(document.documentElement.scrollTop+document.body.scrollTop > 400){
        if(!(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent)))){
            document.getElementById("fankui").style.display = "block";
            document.getElementById("homeSet").style.display = "block";
            document.getElementById("toTop").style.display = "block";
              document.getElementById("minidown").style.display = "block";
        }
    }else{
        document.getElementById("fankui").style.display = "none";
        document.getElementById("homeSet").style.display = "none";
        document.getElementById("toTop").style.display = "none";
          document.getElementById("minidown").style.display = "none";
    }
}



//设为首页
function homeSet(){
    var browserName=navigator.userAgent.toLowerCase();
    if(/theworld/i.test(browserName)){
        document.getElementById("homeSet").href += "#theworld";
    }else if(/lbbrowser/i.test(browserName)){
        document.getElementById("homeSet").href += "#lbbrowser";
    }else if(/bidubrowser/i.test(browserName)){
        document.getElementById("homeSet").href += "#bidubrowser";
    }else if(/se 2.x/i.test(browserName)){
        document.getElementById("homeSet").href += "#sougou";
    }else if(/360se/i.test(browserName)){
        document.getElementById("homeSet").href += "#browser360";
    }else if(/qqbrowser/i.test(browserName)){
        document.getElementById("homeSet").href += "#qqbrowser";
    }else if(/maxthon/i.test(browserName)){
        document.getElementById("homeSet").href += "#aoyou";
    }else if(/msie/i.test(browserName) && !/opera/.test(browserName)){
        document.getElementById("homeSet").href += "#ie";
    }else if(/firefox/i.test(browserName)){
        document.getElementById("homeSet").href += "#firefox";
    }else if(/opera/i.test(browserName)){
        document.getElementById("homeSet").href += "#opera";
    }else if(/webkit/i.test(browserName) &&!(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))){
        document.getElementById("homeSet").href += "#safari";
    }else if(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)){
        document.getElementById("homeSet").href += "#chrome";
    }
}



/**
 * 栏目定制  定义了一个ajax类
 * @type {Object}
 * @author harleywang@tencent.com
 */
var ColTailor = {
    config: [{id:'finance', name:'财经'}, {id:'sports', name:'体育'}],
    onClose: function(target){
        $(target).parents(".orderContent").removeClass("orderContentRight");
        $(target).parents(".orderContent").hide();
        $(target).parents(".orderLayout").hide();
        $(target).parents(".hd").removeClass("hdHover");

        defaultPuguang("cs_closebutton",1445);
    },
    onReset: function(target){
        if(QQ.Cookie.get("skey")){ //判断是否登录
            $(target).parents(".orderContent").removeClass("orderContentRight");
            $(target).parents(".orderContent").hide();
            $(target).parents(".orderLayout").hide();
            $(target).parents(".hd").removeClass("hdHover");
            QQ.LoadScript("http://i.match.qq.com/qhome/uinterest?callback=contentInit&random="+Math.random(),function(){});
            orderUpdate(0);
        }else{
            userLogin();
        }
        defaultPuguang("cs_defult",1445);
    }
};

        
//生成随机数
var dateTime = new Date();
var lastDay = dateTime.getFullYear() + '-' + (dateTime.getMonth()+1) + '-' + dateTime.getDate();        

parseInt(1.1)*Math.random()*1000        
        
        
        
        
        
        //搜狗灰度
function sogouGray(){
    var uinStr = QQ.Cookie.get("uin") || QQ.Cookie.get("luin") || QQ.Cookie.get("pt2qquin") || QQ.Cookie.get("o_cookie") || "";
    uinStr = parseInt(Number(uinStr.replace("o",""))).toString();
    if(uinStr.charAt(uinStr.length-4) == 1 || uinStr.charAt(uinStr.length-4) == 2 || uinStr.charAt(uinStr.length-4) == 3){ //搜狗灰度1;QQ倒数第四位为1、2、3
        document.getElementById("searchBtn").className = "sougouGray";
        document.getElementById("sougouTxt").style.width = "200px";
        document.getElementById("searchTxt").style.width = "315px";
        document.getElementById("searchBtn").onclick = function(){
            registerZone2({bossZone:'searchbutton_g1',url:''},1);
        }
        document.getElementById("sogouLogoLink").onclick = function(){
            registerZone2({bossZone:'searchlogo_g1',url:''},1);
        }
        document.getElementById("sogouLogoLink").href = "https://www.sogou.com/?pid=sogou-wsse-3f7bcd0b3ea82268-0002";
        document.getElementById("searchForm").setAttribute("action","https://www.sogou.com/sogou?pid=sogou-wsse-3f7bcd0b3ea82268-0002&ie=utf-8&query=");
        return false;
    }else if(uinStr.charAt(uinStr.length-4) == 4 || uinStr.charAt(uinStr.length-4) == 5 || uinStr.charAt(uinStr.length-4) == 6){ //搜狗灰度2;QQ倒数第四位为4、5、6
        document.getElementById("searchBtn").className = "sougouGray2";
        document.getElementById("sougouTxt").style.width = "212px";
        document.getElementById("searchTxt").style.width = "327px";
        document.getElementById("searchBtn").onclick = function(){
            registerZone2({bossZone:'searchbutton_g2',url:''},1);
        }
        document.getElementById("sogouLogoLink").onclick = function(){
            registerZone2({bossZone:'searchlogo_g2',url:''},1);
        }
        document.getElementById("sogouLogoLink").href = "https://www.sogou.com/?pid=sogou-wsse-3f7bcd0b3ea82268-0003";
        document.getElementById("searchForm").setAttribute("action","https://www.sogou.com/sogou?pid=sogou-wsse-3f7bcd0b3ea82268-0003&ie=utf-8&query=");
        return false;
    }else{
        document.getElementById("searchForm").setAttribute("action","https://www.sogou.com/sogou?pid=sogou-wsse-3f7bcd0b3ea82268-0001&ie=utf-8&query=");
    }
}