简体   繁体   English

在浏览器中检查是否已安装torrent-client

[英]Check in browser is torrent-client installed

Is there a way in javascript to check if magnet link is supported by browser (= to check if torrent client is installed on user's pc)? javascript中有没有办法检查浏览器是否支持磁铁链接(=检查用户的PC上是否安装了torrent客户端)?

I want to check via javascript if browser opens torrent client by clicking on magnet link or I need to show some additional instructions (if torrent client is not installed). 我想通过JavaScript检查浏览器是否通过单击磁铁链接打开torrent客户端,或者我需要显示一些其他说明(如果未安装torrent客户端)。

Being a Browser, it has no access to installed applications in the OS, but what it does have is access to a list of supported MIME types. 作为浏览器,它无权访问操作系统中已安装的应用程序,但确实具有访问受支持的MIME类型的列表的权限。

In JavaScript you can check it as follows: 在JavaScript中,您可以按以下方式进行检查:

var mimeCheck = function (type) {
    return Array.prototype.some.call(navigator.plugins, function (plugin) {
        return Array.prototype.some.call(plugin, function (mime) {
            return mime.type == type;
        });
    });
};

Thanks to this previously asked question . 由于这个先前提出的问题

Here is a fiddle The MIME type I use is application/x-bittorrent 这是一个小提琴 。我使用的MIME类型是application / x-bittorrent

EDIT: As pointed out by @HaukurHaf, this will only work if the client has an extension installed for torrents in the browser itself. 编辑:正如@HaukurHaf所指出的,只有在客户端在浏览器本身中为torrent安装了扩展名的情况下,这才起作用。 So this might or might not return true for some clients. 因此,对于某些客户端,这可能会返回true,也可能不会返回true。

No, not with javascript. 不,不是使用javascript。 Imagine if plain javascript could check what software users have installed on their machines. 想象一下普通的javascript是否可以检查用户在其计算机上安装了哪些软件。 That would be a huge security risk. 那将是巨大的安全风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM