作者:一直很哇塞 | 来源:互联网 | 2023-05-21 13:47
Stack Overflown在这个问题中提到:
在每个repo上,GitHub都有一个标记为"Clone in Desktop"的按钮(例如:https://github.com/github/developer.github.com).如果您安装了GitHub for Mac,则href类似于"github-mac:// openRepo/https://github.com/github/developer.github.com ".这将打开GitHub for Mac并提供克隆回购.如果不这样做,则href为" http://mac.github.io ".这是GitHub for Mac的下载页面.我想在我的网站上做类似的事情:如果已安装,请打开我的应用程序,如果没有则重定向下载.如何才能最好地完成?
答案是关于Github Conduit,但据我所知,Github Conduit仅适用于Mac的Github.
我有同样的问题,仅适用于Windows操作系统.GitHub如何知道GitHub是否安装在计算机上?
正如deepcurious在说他们的答案,我们需要使用下面的代码,如果协议注册的检查:
$("a[href*='github-windows://']").click(function(e) {
var el = $(this);
setTimeout(function() {
window.location = el.data("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.data("href");
e.preventDefault();
});
我有以下HTML链接:
Clone in Desktop
如果安装了应用程序,Google Chrome会给我一个外部协议请求(如下所示),因此我认为它应该可以正常工作(尽管它在我的计算机上没有任何作用).但是,如果未安装该应用程序,则不会转到该data-href-alt
页面.
例如,如果我改变github-windows://
,以some-uninstalled-app://
在所有情况下的代码,链接什么也不做.
![谷歌Chrome的外部协议请求](https://img.php1.cn/3cd4a/18ace/696/1d8e759bd3e6bbec.jpeg)