zoukankan      html  css  js  c++  java
  • 判断平台以及微信

    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/i) || !!u.match(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/), //是否为移动终端
    ios: !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
    android: u.indexOf('Android') > -1, //android终端或者uc浏览器
    iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
    iPad: u.indexOf('iPad') > -1, //是否iPad
    ios9: u.indexOf('iPhone OS 9') > -1,
    MQQBrowser: u.indexOf('MQQBrowser') > -1, //是否MQQBrowser
    UCBrowser: u.indexOf('UCBrowser') > -1, //UCBrowser
    webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
    };
    } (),
    language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }

    //ios--search & headcata
    $(function(){
    if(browser.versions.ios){
    //$('#bdcs-search-form input[name="nsid"]').attr('value','6');
    }
    if(browser.versions.android){
    //$('#bdcs-search-form input[name="nsid"]').attr('value','3');
    };

    //判断是否在微信中打开
    function is_weixin() {
    var uaa = navigator.userAgent.toLowerCase();
    var odocumentH=$(document).height();
    var owindowW=$(window).width();
    var kg=true;
    if (uaa.indexOf('micromessenger')>0) {
    /**如果是微信执行语句**/
    };
    };
    $('#info #btns a').click(is_weixin); //事件执行


    })

    2.判断浏览器内核以及浏览器名称

    //浏览器信息
    var browser = (function(){
    	var u = navigator.userAgent;
    	var obj = {
    		//内核
    		isTrident: u.indexOf('Trident')>0,
    		isPresto: u.indexOf('Presto')>0,
            isWebKit: u.indexOf('AppleWebKit')>0,
            isGecko: u.indexOf('Gecko')>0,
    		//浏览器
    		isUC: u.indexOf('UC')>0||u.indexOf('UBrowser')>0,
    		isQQ: u.indexOf('QQBrowser')>0,
    		isBaiDu: u.indexOf('Baidu')>0||u.indexOf('BIDUBrowser')>0,
    		isMaxthon: u.indexOf('Maxthon')>0,
    		isSouGou: u.indexOf('MetaSr')>0||u.indexOf('Sogou')>0,
    		isIE: u.indexOf('MSIE')>0,
    		isFirefox: u.indexOf('Firefox')>0,
    		isOpera: u.indexOf('Opera')>0||u.indexOf('OPR')>0,
    		isSafari: u.indexOf('Safari')>0,
    		isChrome:u.indexOf('Chrome')>0||u.indexOf('CriOS')>0,
    		//系统或平台
    		isWindows:u.indexOf('Windows')>0,
    		isMac:u.indexOf('Macintosh')>0,
    		isAndroid:u.indexOf('Android')>0||u.indexOf('Adr')>0,
    		isWP:u.indexOf('IEMobile')>0,
    		isBlackBerry:u.indexOf('BlackBerry')>0||u.indexOf('RIM')>0||u.indexOf('BB')>0,
    		isMeeGo:u.indexOf('MeeGo')>0,
    		isSymbian:u.indexOf('Symbian')>0,
    		isIOS:u.indexOf('like Mac OS X')>0,
    		isIPhone: u.indexOf('iPh')>0,
    		isIPad:u.indexOf('iPad')>0,
    		//设备
    		isMobile:u.indexOf('Mobi')>0||u.indexOf('iPh')>0||u.indexOf('480')>0,
    		isTablet:u.indexOf('Tablet')>0||u.indexOf('iPad')>0||u.indexOf('Nexus 7')>0,
    		//语言
    		language: (function(){
    			var g = (navigator.browserLanguage || navigator.language).toLowerCase();
    			return g=="c"?"zh-cn":g;
    		})()
    	}
    	//修正
    	if(!obj.isTrident){
    		obj.isTrident = obj.isIE;
    	}
    	if(obj.isGecko){
    		obj.isGecko = !obj.isWebKit;
    	}
    	if(obj.isChrome){
    		obj.isChrome = !(obj.isOpera + obj.isBaiDu + obj.isMaxthon + obj.isSouGou + obj.isUC + obj.isQQ);
    	}
    	if(obj.isSafari){
    		obj.isSafari = !(obj.isChrome + obj.isOpera + obj.isBaiDu + obj.isMaxthon + obj.isSouGou + obj.isUC + obj.isQQ);
    	}
    	if(obj.isMobile){
    		obj.isMobile = !obj.isIPad;
    	}
    	return obj;
    })();

    调用方式
    <!DOCTYPE html>
    <html lang="zh-CN">
        <head>
            <meta charset="UTF-8">
            <title>浏览器测试</title>
            <script src="../code/browser.js"></script>
        </head>
        <body>
            <script>
                    document.writeln("appVersion:"+navigator.appVersion+"<br/>");
                    document.writeln("userAgent:"+navigator.userAgent+"<br/>");
    
                    document.writeln("语言:"+browser.language+"<br/>");
                    document.writeln("<h2>内核</h2>");
                    document.writeln("是否为IE内核:"+browser.isTrident+"<br/>");
                    document.writeln("是否为opera内核:"+browser.isPresto+"<br/>");
                    document.writeln("是否为Webkit内核:"+browser.isWebKit+"<br/>");
                    document.writeln("是否为火狐内核:"+browser.isGecko+"<br/>");
                    document.writeln("<h2>浏览器</h2>");
                    document.writeln("是否为IE浏览器:"+browser.isIE+"<br/>");
                    document.writeln("是否为Chrome浏览器:"+browser.isChrome+"<br/>");
                    document.writeln("是否为Firefox浏览器:"+browser.isFirefox+"<br/>");
                    document.writeln("是否为Opera浏览器:"+browser.isOpera+"<br/>");
                    document.writeln("是否为UC浏览器:"+browser.isUC+"<br/>");
                    document.writeln("是否为QQ浏览器:"+browser.isQQ+"<br/>");
                    document.writeln("是否为百度浏览器:"+browser.isBaiDu+"<br/>");
                    document.writeln("是否为搜狗浏览器:"+browser.isSouGou+"<br/>");
                    document.writeln("是否为Safari:"+browser.isSafari+"<br/>");
                    document.writeln("<h2>操作系统</h2>");
                    document.writeln("是否为android:"+browser.isAndroid+"<br/>");
                    document.writeln("是否为wp:"+browser.isWP+"<br/>");
                    document.writeln("是否为BlackBerry:"+browser.isBlackBerry+"<br/>");
                    document.writeln("是否为MeeGo:"+browser.isMeeGo+"<br/>");
                    document.writeln("是否为Symbian:"+browser.isSymbian+"<br/>");
                    document.writeln("是否为Windows:"+browser.isWindows+"<br/>");
                    document.writeln("是否为Mac:"+browser.isMac+"<br/>");
                    document.writeln("是否为iOS:"+browser.isIOS+"<br/>");
                    document.writeln("是否为iphone:"+browser.isIPhone+"<br/>");
                    document.writeln("是否为ipad:"+browser.isIPad+"<br/>");
                    document.writeln("<h2>设备</h2>");
                    document.writeln("是否为手机:"+browser.isMobile+"<br/>");
                    document.writeln("是否为平板:"+browser.isTablet+"<br/>");
            </script>
        </body>
    </html>

    链接地址:http://passer-by.com/
  • 相关阅读:
    TCL 双引号和花括号的区别
    在Vivado中调用ModelSim生成FSM的状态转移图
    基于配置文件的方式来配置AOP
    Spring MVC_Hello World
    重用切点表达式
    Spring MVC概述(2)
    Shiro_DelegatingFilterProxy
    Shiro-工作流程
    切面的优先级
    Shiro-集成Spring
  • 原文地址:https://www.cnblogs.com/cainiaoz/p/5108752.html
Copyright © 2011-2022 走看看