Browse Source

userAgent

tik5213 9 years ago
parent
commit
db800c33c1
2 changed files with 23 additions and 11 deletions
  1. 2 1
      general-web-server/web/myindex.html
  2. 21 10
      general-web-server/web/res/js/wade-mobile.js

+ 2 - 1
general-web-server/web/myindex.html

@ -16,7 +16,8 @@
16 16
	<body>
17 17
		<script type="text/javascript">
18 18
			//WadeMobile.tip("你好,我好,大家好………………");
19
			alert(window.navigator.userAgent);
19
			//alert(window.navigator.userAgent);
20
			alert("app:" + WadeMobile.isApp() + "\nandroid:" + WadeMobile.isAndroid() + "\nios:" + WadeMobile.isIOS());
20 21
		</script>
21 22
		<h1>myindex</h1>
22 23
		<br /><br />

+ 21 - 10
general-web-server/web/res/js/wade-mobile.js

@ -4,15 +4,26 @@
4 4
window.Mobile = window.WadeMobile = (function() {
5 5
	//终端类型,a为android,i为ios
6 6
	var deviceType = (function(){
7
		var sUserAgent = navigator.userAgent.toLowerCase();
8
		var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
9
		var bIsIphone = sUserAgent.match(/iphone os/i) == "iphone os";
10
		var bIsAndroid = sUserAgent.match(/android/i) == "android";
11
		var bIsWinphone = sUserAgent.match(/windows phone /i) == "windows phone " || sUserAgent.match(/windows phone os /i) == "windows phone os ";
12
		if(bIsAndroid){
13
			return "a";
14
		}else if(bIsIpad||bIsIphone){
15
			return "i";
7
		/*
8
		IpuMobile/i1/android/00/2.0/Hybrid
9
        userAgent格式
10
        i1版本规范:
11
        标识符/规范版本号/终端类型(ios,android,wp)/终端型号(平板,或尺寸,00表示默认)/框架版本号/结尾标识符
12
        */
13
		var sUserAgent = window.navigator.userAgent;
14
		//          标识符     规范1  类型2 型号3  框架4 结尾标识符
15
		var re = /IpuMobile\/(.*)\/(.*)\/(.*)\/(.*)\/Hybrid/ig
16
		var arrMessages = re.exec(sUserAgent);
17
		if(arrMessages && arrMessages[1] =="i1" ){
18
			if(arrMessages[2] == "android"){
19
				return "a";
20
			}else if(arrMessages[2] == "ios"){
21
				return "i"
22
			}else if(arrMessages[2] == "wp"){
23
				return "w";
24
			}else{
25
				return null;
26
			}
16 27
		}else{
17 28
			return null;
18 29
		}
@ -30,7 +41,7 @@ window.Mobile = window.WadeMobile = (function() {
30 41
        	},isWP:function(){
31 42
        		return terminalType=='w';
32 43
        	},isApp:function(){//判断是否是APP应用
33
				return terminalType!=null;
44
				return !!terminalType;
34 45
        	},getSysInfo:function(callback,key,err){//TELNUMBER|IMEI|IMSI|SDKVERSION|OSVERSION|PLATFORM|SIMNUMBER
35 46
				WadeMobile.callback.storageCallback("getSysInfo",callback);
36 47
				execute("getSysInfo", [key],err);