如何检查应用程序是否从 Web 浏览器安装?



这是针对Windows的。

我有一个闪存应用程序,我正在转换为 AIR。我使用 NSIS 构建了一个强制安装程序,它工作正常。但是,我想在网站上有一个图标,用于检查应用程序是否已安装并询问用户是否希望运行它。如果未安装,则可以选择下载它。

我相当确定这是可行的,因为Zoom和GoToMeeting都这样做。

在寻找这个时,我的搜索技能似乎让我失败了。

编辑:

似乎最好的/唯一的方法是为应用程序创建自定义协议。像 DoDaApp://。

这带来了下一组问题;

  1. 如何创建一个NSIS文件,该文件将在客户端计算机上创建适当的注册表项?以用户身份,而不是管理员身份。
  2. 如何检查该协议当前是否安装在计算机上?

这是一个部分答案,因为它在 Edge 中不起作用。我将在下面解释这个问题。

按照如何检测浏览器的协议处理程序中的建议,您可以使用超时和模糊事件处理程序。这是我对代码的解释;

function checkCustomProtocol(inProtocol,inInstalLink,inTimeOut)
{
var timeout = inTimeOut;
window.addEventListener('blur',function(e)
{
window.clearTimeout(timeout);
}
)
timeout = window.setTimeout(function() 
{
console.log('timeout');
window.location = inInstalLink;
}, inTimeOut
);
window.location = inProtocol;
}

Microsoft Edge通过弹出一个对话框告诉您"您需要一个新应用程序才能打开它"非常有用,该对话框会"模糊"屏幕,不允许下载文件。

因此,我将发布另一个关于如何使其在Edge中工作的问题。我已经查看了ismailhabib的代码,但已知问题部分说它也不能与Edge一起使用。

这是一个更完整的答案。它已经在IE 11,Microsoft Edge,Chrome和Firefox中进行了轻微测试。我还添加了评论;

/*
checkCustomProtocol - check if custom protocol exists
inProtocol - URL of application to run eg: MyApp://
inInstallLink - URL to run when the protocol does not exist.
inTimeOut - time in miliseconds to wait for application to Launch.
*/
function checkCustomProtocol(inProtocol,inInstalLink,inTimeOut)
{
// Check if Microsoft Edge
if (navigator.msLaunchUri)
{
navigator.msLaunchUri(inProtocol, function () 
{
//It launched, nothing to do
},
function()
{
window.location = inInstalLink; //Launch alternative, typically app download.
}
);
}
else
{
// Not Edge
var timeout = inTimeOut;
//Set up a listener to see if it navigates away from the page.
// If so we assume the papplication launched
window.addEventListener('blur',function(e)
{
window.clearTimeout(timeout);
}
)
//Set a timeout so that if the application does not launch within the timeout we 
// assume the protocol does not exist
timeout = window.setTimeout(function() 
{
console.log('timeout');
window.location = inInstalLink; //Try to launch application
}, inTimeOut
);
window.location = inProtocol; //Launch alternative, typically app download.
}
}

最新更新