2

I am developing a website. In my website, I have created some applications and the buttons linked to those applications. Once the users click on the button, the users will be prompted to install the application.

My question is:

If the users had not installed the applications in their PC, so they will be prompted to install the applications in their PC once they click on the buttons; but if they had already installed the applications on their PC, the application should reject or alert the users that the same application is already installed.

So, how should I write the code to detect or to check the applications whether they had already been installed into the users'PC?

4

1 回答 1

1

你有几个选择

  1. 哑剧类型

    在大多数浏览器(不是 IE)上,您可以看到已定义的 mime 处理程序,例如 application/foo。然后你可以遍历navigator.mimeTypes,看看它是否存在。它不是一个数组(严格来说),所以你需要转换它。

    var mimes = Array.prototype.slice.call(navigator.mimeTypes)
    if (mimes.length && mimes.indexOf("application/foo") !== -1) {
        // we've got it!
    }
    else {
        // we're on IE and/or the app isn't installed
    }
    
  2. 扩展/插件

    除了您的应用程序的正常行为外,它还可以在用户的​​浏览器中安装一个非常简单且小型的扩展程序。该扩展将实现一个内容脚本,该脚本仅在您的网站上处于活动状态,并将“下载”按钮替换为“运行”按钮。可能有点矫枉过正,并且惹恼了用户。

  3. 注册一个自定义://uri

    自定义 URI 允许您使用这个巧妙的技巧。如果您的应用未安装,它将无法重定向,并且会加载 downloadURL。例如itunes://foobar,如果您安装了 iTunes,请尝试将 appurl 更改为 。

    var appurl = 'myapp://launch';
    var downloadURL = '/installer.exe';
    
    var timeout;
    
    function preventPopup() {
        clearTimeout(timeout);
        timeout = null;
        window.removeEventListener('pagehide', preventPopup);
    }
    
    function startApp() {
        document.location = appurl;
        timeout = setTimeout(function () {
            location.href = downloadURL;
        }, 1000);
        window.addEventListener('pagehide', preventPopup);
    }
    
    startApp();
    

    这可能是最好的解决方案。

于 2013-08-27T04:24:56.697 回答