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!
A browser usually identifies a resource's MIME type by observing the Content-Type response header in an HTTP response. Sometimes, developers set values for Content-Type headers that are not appropriate for the response's content.
The application uses file content sniffers to search for a particular pattern in the file. A file content sniffer associates a specific pattern in a file with a MIME type. If the application finds a match for the pattern, the MIME type associated with the pattern is the MIME type of the file.
Use the guess_type() function to guess the MIME type based on a filename or URL. A tuple of (type, encoding) is returned. The first element of the tuple, type , is the MIME type. The second element, encoding , is a value if the file is compressed with gzip , for example.
MIME stands for "Multipurpose Internet Mail Extensions". The concept of MIME Types was originally created to be used with email programs; hence the "Mail" part of the acronym. MIME Types are now also used by web browsers.
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);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With