Check Browser Support for specific Mime Type?

Windwalker picture Windwalker · Feb 12, 2013 · Viewed 7.5k times · Source

For a web application which allows in-browser preview of documents, I'd like to check whether the user's browser supports preview of the current document's mime type.

Is there a Javascript-based way to match the current mime type against the types supported by the browser?

Thanks!

Answer

Тёма Пендюрин picture Тёма Пендюрин · Sep 24, 2014

In recent browsers there are navigatior.plugins array-like object. You can check each plugin for your mime type.

Here is the solution gist and jsfiddle.

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