Check if URL scheme is supported in javascript

2019-01-02 14:40发布

Is there any way to check if a URL scheme is currently registered on the phone... with javascript?

10条回答
忆尘夕之涩
2楼-- · 2019-01-02 15:14

I have this comment https://stackoverflow.com/a/18715513/49114 with a jQuery plugin to add alternative app link to regular links.

查看更多
姐姐魅力值爆表
3楼-- · 2019-01-02 15:16

Here is a variation on the previous 2 solutions. It will create a link that can be opened in Google Chrome. If it fails it opens the link using http

<script>
 function checkChrome(h){
  document.location=h;
  var time = (new Date()).getTime();
  setTimeout(function(){
   var now = (new Date()).getTime();
   if((now-time)<400) {
    if(confirm('Missing Chrome. Download it now?')){
     document.location = 'http://itunes.apple.com/us/app/chrome/id535886823?mt=8';
    } else {
     document.location=h.replace('googlechrome','http');
    }
   }
  }, 300);
 }
</script>

<a href="googlechrome://www.google.com" onclick="checkChrome(this.href);return false;">Open Google with Chrome</a>
查看更多
临风纵饮
4楼-- · 2019-01-02 15:19

Here is a solution that does not show the popup when you come back from the app, it assumes you've been gone longer than 400 ms:

function startiThrown() {
    document.location = appurl;
    var time = (new Date()).getTime();
    setTimeout(function(){
        var now = (new Date()).getTime();

        if((now - time)<400) {
            if(confirm('You do not seem to have iThrown installed, do you want to go download it now?')){
            document.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=293049283&mt=8&uo=6';
            }
         }
    }, 300);
}
查看更多
心情的温度
5楼-- · 2019-01-02 15:21

Starting from iOS 6.0 Apple presented the Smart App Banners which do what most of us are looking for:

  • Send to App Store if the app isn't installed.
  • Open the App with a specific deep link, using the app-argument param.

Include the following meta tag:

<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">

taken from here: Safari Web Content Guide

查看更多
登录 后发表回答