01 |
if (navigator.userAgent.match(/android/i))
{ |
02 |
//
通過iframe的方式試圖打開APP,如果能正常打開,會直接切換到APP,並自動阻止a標籤的默認行爲 |
03 |
//
否則打開a標籤的href鏈接 |
04 |
var isInstalled; |
05 |
//下面是安卓端APP接口調用的地址,自己根據情況去修改 |
06 |
var ifrSrc
= 'AppProtocolHeader://camnpr? type=0&id=${com.id}&phone_num=${com.phone_num}' ; |
07 |
var ifr
= document.createElement( 'iframe' ); |
08 |
ifr.src
= ifrSrc; |
09 |
ifr.style.display
= 'none' ; |
10 |
ifr.onload
= function ()
{ |
11 |
//
alert('Is installed.'); |
12 |
isInstalled
= true ; |
13 |
alert(isInstalled); |
14 |
document.getElementById( 'openApp0' ).click();}; |
15 |
ifr.onerror
= function ()
{ |
16 |
//
alert('May be not installed.'); |
17 |
isInstalled
= false ; |
18 |
alert(isInstalled); |
19 |
} |
20 |
document.body.appendChild(ifr); |
21 |
setTimeout( function ()
{ |
22 |
document.body.removeChild(ifr); |
23 |
},1000); |
24 |
} |
25 |
26 |
//ios判斷 |
27 |
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) |
28 |
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
{ |
30 |
var isInstalled; |
31 |
//var
gz = '{"comName":"${com.short_name}","comID":"${com.id}","comPhoneNum":"${com.phone_num}","type":"0"}'; |
32 |
//var
jsongz =JSON.parse(gz); |
33 |
34 |
//下面是IOS調用的地址,自己根據情況去修改 |
35 |
var ifrSrc
= 'AppProtocolHeader://?comName=${com.short_name}&comID=${com.id}&comPhoneNum=${com.phone_num}&type=0' ; var ifr
= document.createElement( 'iframe' ); |
36 |
ifr.src
= ifrSrc; |
37 |
ifr.style.display
= 'none' ; |
38 |
ifr.onload
= function ()
{ |
39 |
//
alert('Is installed.'); |
40 |
isInstalled
= true ; |
41 |
alert(isInstalled); |
42 |
document.getElementById( 'openApp1' ).click();}; |
43 |
ifr.onerror
= function ()
{ |
44 |
//
alert('May be not installed.'); |
45 |
isInstalled
= false ; |
46 |
alert(isInstalled); |
47 |
} |
48 |
document.body.appendChild(ifr); |
49 |
setTimeout( function ()
{ |
50 |
document.body.removeChild(ifr); |
51 |
},1000); |
52 |
} |
53 |
} |