短信链接打开app

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script src="./resources/api/bootstrap/js/jquery-2.0.3.js"></script>
</head>
<body>
    <script type="text/javascript">
        var iosurl = "https://itunes.apple.com/us/app/";
        var android = "http://www.baidu.com";
        var baidu = "http://www.baidu.com";
        var hao = "http://www.hao123.com";
        var open;
        function IsIOS() {
            var userAgentInfo = navigator.userAgent;
            var Agents = [ "iPhone", "Windows Phone", "iPad", "iPod" ];
            var flag = true;
            for (var v = 0; v < Agents.length; v++) {
                if (userAgentInfo.indexOf(Agents[v]) > 0) {
                    flag = false;
                    break;
                }
            }
            return flag;
        }
         
        function IsAndroid() {
            var userAgentInfo = navigator.userAgent;
            var Agents = [ "Android", "SymbianOS" ];
            var flag = true;
            for (var v = 0; v < Agents.length; v++) {
                if (userAgentInfo.indexOf(Agents[v]) > 0) {
                    flag = false;
                    break;
                }
            }
            return flag;
        }
         
        $(window).load(function (){
            if(!IsIOS()){
                var ifr = document.createElement('iframe');
                ifr.src = 's1e://';//打开app的协议,有app同事提供
                ifr.style.display = 'none';
                document.body.appendChild(ifr);
                window.setTimeout(function(){
                    document.body.removeChild(ifr);
                    window.location.href = iosurl;
                },2000);
            }else
            if(!IsAndroid()){
                window.location.href = "openapp://1.2.com/unread";
                window.setTimeout(function(){
                   window.location.href = android;
                },2000);
            }else{
                btn_get_click();
            }
             
             
            function btn_get_click() {
                var xmlHttp = window.XMLHttpRequest ?
                    new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
 
                //添加参数,以求每次访问不同的url,以避免缓存问题
                xmlHttp.open("get", "www.hao123.com");
                 
                xmlHttp.onreadystatechange = function () {
                    console.log(xmlHttp.status);
                    if (xmlHttp.status == 200) {
                        window.location.href = hao;
                    }
                    if (xmlHttp.status == 404) {
                        window.location.href = baidu;
                    }
                }
                //发送请求,参数为null
                xmlHttp.send(null);
            }
        });
         
         
    </script>
</body>
</html>

  

 

更精确的判断,区别版本号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html > 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"></meta> 
    <title></title> 
    <meta charset="UTF-8"
    <style type="text/css"
        html,body{ 
            height:100%; 
            margin: 0px; 
            padding: 0px; 
        
        body { 
            background-image: url(/system/common/images/wei_down_bg.png);   //用于提示微信,QQ用户在浏览器中打开此网页面 
            background-position: center center; 
            background-repeat: no-repeat; 
            background-attachment: fixed
            background-size: cover; 
        
    </style> 
       
    <script type="text/javascript" src="./resources/api/bootstrap/js/jquery-2.0.3.js"></script> 
 
</head> 
<body> 
<a href="shiyantaihe://" id="openApp"></a>
</body>
    <script type="text/javascript"
    var openAppHref,officialHref; 
    var browser = { 
        ua: function () { 
            var u = navigator.userAgent; 
            var isChrome = u.match(/Chrome\/([\d.]+)/) || u.match(/CriOS\/([\d.]+)/); 
            var isAndroid = u.match(/(Android);?[\s\/]+([\d.]+)?/); 
            var iosVersion = function () { 
                if (/iP(hone|od|ad)/.test(navigator.platform)) { 
                    var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); 
                    return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; 
                
            }(); 
            var chromeVersion = function () { 
                var chrome = navigator.userAgent.match(/Chrome\/(\d+)\./); 
                if (chrome) { 
                    return parseInt(chrome[1], 10); 
                
            }(); 
            var ios9 = iosVersion && iosVersion[0] >= 9; 
            var chrome18 = isChrome && isAndroid && chromeVersion && chromeVersion > 18; 
            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应该程序,没有头部与底部 
                weChat: u.indexOf('MicroMessenger') > -1, 
                UC: u.indexOf('UCBrowser') > -1, 
                u3: u.indexOf('U3') > -1, 
                chrome: u.indexOf('Chrome') > -1, 
                windowsPhone: u.indexOf("Windows Phone") > -1, 
                samsung: u.indexOf("Samsung") > -1, 
                QQ: (u.match(/\sQQ/i)!=null ? u.match(/\sQQ/i).toLowerCase() == " qq":false), 
                isChrome: isChrome, 
                isAndroid: isAndroid, 
                iosVersion: iosVersion, 
                chromeVersion: chromeVersion, 
                ios9: ios9, 
                chrome18: chrome18 
            }; 
        }() 
    
    var ua = browser.ua; 
    /** 
     * 尝试跳转openAppHref,如果跳转失败,进入officialHref 
     */ 
    function timeoutRedirect() { 
        var startTime = Date.now(); 
        var timeout = 500; 
        openApp(); 
        var t = setTimeout(function () { 
            var endTime = Date.now(); 
            if (endTime - startTime < timeout + 100) {   //若启动应用,则js会被中断较长时间,超出此范围 
                if (ua.ios9) {   //ios9会弹出确认按钮,时间一定会超出 
                    openH5();    //此处请各位自行处理,暂时没有找到好的办法 
                    return
                
                openH5(); 
            
        }, timeout); 
        window.beforeunload = function () { 
            clearTimeout(t); 
        
        window.pagehide = function () { 
            clearTimeout(t); 
        
        window.onblur = function () { 
            clearTimeout(t); 
        
    
    function openH5() { 
        window.location.href = officialHref; 
    
    function openApp() { 
        openAppByIframe(); 
        if (ua.ios9) { 
            window.location = openAppHref; 
            //document.getElementById('openApp').click();
            return
        
        if (ua.chrome18) { 
            window.location = openAppHref; 
            return
        
    
    function openAppByIframe() { 
        if (!openAppHref ) { 
            window.location = officialHref; 
            return
        
        if (ua.android) {  
            window.location = openAppHref; 
            return
        
        if (ua.ios9) {return;} 
        var iframe = document.createElement("iframe"); 
        iframe.style.display = "none"
        iframe.style.border = "none"
        iframe.style.width = "1px"
        iframe.style.height = "1px"
        iframe.src = openAppHref; 
        document.body.appendChild(iframe); 
    
       
    $(function () { 
        if (ua.android) { 
            openAppHref =  "android协议";//打开某手机上的某个app应用, myapp需要与android配制对应 
            officialHref = "http://"
        } else if (ua.iOS){ 
            openAppHref =  "ios协议";//打开某手机上的某个app应用 
            officialHref = "https://itunes.apple.com/"
        
        if (ua.weChat && ua.iOS) { //iOS上的微信webview 
            return
        } else if (ua.weChat && ua.android) { //安卓上的微信webview 
            return
        } else if (ua.windowsPhone) {//winphone 
            return
        } else
            if ((ua.UC && ua.android && !ua.u3 && !ua.chrome)) { 
                //浏览器不支持 
                return
            } else
                //chrome某些版本不允许自动进入app,手动点击触发重定向 
                timeoutRedirect(); 
            
        
    }) 
    </script>  
</html>

  

posted @   斌灬小生不才  阅读(1011)  评论(0编辑  收藏  举报
编辑推荐:
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· ASP.NET Core - 日志记录系统(二)
· .NET 依赖注入中的 Captive Dependency
· .NET Core 对象分配(Alloc)底层原理浅谈
· 聊一聊 C#异步 任务延续的三种底层玩法
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(一):从.NET IoT入
· .NET 开发的分流抢票软件,不做广告、不收集隐私
· ASP.NET Core - 日志记录系统(二)
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· 实现windows下简单的自动化窗口管理
点击右上角即可分享
微信分享提示