Stack Overflown在 this question 中询问:
On every repo, GitHub has a button that is labelled "Clone in Desktop" (example: https://github.com/github/developer.github.com). If you have GitHub for Mac installed, the href is something like "github-mac://openRepo/https://github.com/github/developer.github.com". This opens GitHub for Mac and offers to clone the repo. If you don't, the href is "http://mac.github.io". This is a download page for GitHub for Mac. I would like to do something similar on my website: open my app if installed and redirect to download if not. How can this be best accomplished?
答案大约是 Github Conduit ,但是,据我所知,Github Conduit 仅适用于 Github for Mac .
我有同样的问题,仅适用于 Windows 操作系统。 GitHub 如何知道计算机上是否安装了 GitHub?
作为deepcurious在 their answer 中说,我们需要使用以下代码来检查协议(protocol)是否已注册:
$("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 链接:
<a href="github-windows://openRepo/https://github.com/jquery/api.jqueryui.com" data-href-alt="https://www.example.com/app-not-installed">Clone in Desktop</a>
如果安装了该应用程序,谷歌浏览器会向我提供一个外部协议(protocol)请求(如下),因此我认为它应该可以正常工作(尽管它在我的计算机上没有任何作用)。但是,如果未安装该应用程序,它不会转到 data-href-alt
页面。
例如,如果我在代码的所有实例中将 github-windows://
更改为 some-uninstalled-app://
,则该链接不执行任何操作。
最佳答案
的确,GitHub Conduit 仅适用于 GitHub for Mac。那么GitHub官网是如何判断是否安装了GitHub for Windows的呢?
嗯,GitHub for Windows 在这方面显然没有那么复杂。 “在桌面上克隆”只有在您安装了适用于 Windows 的 GitHub 并使用选项下的“添加帐户”按钮验证了您的帐户后才能使用。
完成此操作后,只要登录到添加到 GitHub for Windows 的 GitHub 帐户,“在桌面上克隆”链接将具有 github-windows://
协议(protocol),而不是 https://windows.github.com/
链接。
但是,如果您在未安装 GitHub for Windows 的计算机上登录 GitHub 并单击该按钮,会发生什么情况?它具有相同的链接,但由于显而易见的原因而无法使用。
是的,GitHub 显然盲目地假设当您在 Windows 计算机上使用您的帐户时,您必须安装 GitHub for Windows。
关于windows - 启动应用程序(如果已安装)或重定向以下载 - Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28592409/