问题描述
javascript中是否有方法检查浏览器是否支持磁力链接(=检查用户计算机上是否安装了torrent客户端)?
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检查浏览器是否通过单击磁铁链接打开torrent客户端,或者我需要显示一些其他说明(如果未安装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).
推荐答案
作为浏览器,它无法访问操作系统中已安装的应用程序,但是它具有访问受支持的MIME类型列表的权限.
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.
在JavaScript中,您可以按以下方式进行检查:
In JavaScript you can check it as follows:
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;
});
});
};
感谢此先前提出的问题.
这是小提琴我使用的MIME类型是 application/x-bittorrent
Here is a fiddleThe MIME type I use is application/x-bittorrent
如@HaukurHaf所指出的,只有在客户端在浏览器本身中为torrent安装了扩展名的情况下,此方法才起作用.因此,对于某些客户端,这可能会返回true,也可能不会返回true.
As pointed out by @HaukurHaf, this will only work if the client has an extension installed for torrents in the browser itself. So this might or might not return true for some clients.
这篇关于在浏览器中检查是否已安装torrent-client的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!