simplest cross-browser check if protocol handler is registered

后端 未结 5 1417
青春惊慌失措
青春惊慌失措 2020-12-02 14:47

When user clicks link with custom protocol (like myapp://superlink)

I need either launch an app or allow user to download and run configuration app

5条回答
  •  天命终不由人
    2020-12-02 15:07

    Update to Korono's answer, this worked for me:

    $(function() {
        var timeIndex;
        $("a[href*='myapp://']").blur(function(e)
        {
            clearTimeout(timeIndex);
        });
    
        $("a[href*='myapp://']").click(function(e)
        {
          var el = $(this);
          timeIndex = setTimeout(function() {
            window.location = el.attr("data-href-alt");
          }, 200);
    
          // once you do the custom-uri, it should properly execute the handler, otherwise, the settimeout that you set before will kick in
          window.location = el.attr("href");
          e.preventDefault();
        });
    });
    

提交回复
热议问题