问题
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)?
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).
回答1:
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.
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;
});
});
};
Thanks to this previously asked question.
Here is a fiddle The MIME type I use is 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. So this might or might not return true for some clients.
回答2:
No, not with javascript. Imagine if plain javascript could check what software users have installed on their machines. That would be a huge security risk.
来源:https://stackoverflow.com/questions/34044773/check-in-browser-is-torrent-client-installed