问题
I found how to get mimetypes from navigator.mimeTypes:
function GetMimeTypes() {
var message = "";
var mimes = navigator.mimeTypes;
for (var i = 0; i < mimes.length; i++) {
message += "<b>" + mimes[i].type + "</b> : " + mimes[i].description + "/" + mimes[i].suffixes + "<br />";
}
var info = document.getElementById("mime");
info.innerHTML = message;
}
but it doesn't return types like text/html, text/css or text/javascript. I found: Naturally,several MIME types are handled by the browser itself, such as text/javascript(JavaScript files), text/css (CSS style sheets), image/gif (GIF-encoded images), image/jpegimages),text/xml (XML files), and text/html(HTML files). Many others, however, are handled by plugins and checker navigator.mimeTypes[“text/html”] != null, how can i get list of these?
回答1:
Using your code in Google Chrome/Firefox I get:
application/vnd.chromium.remoting-viewer : /
pepper-application/x-chromoting : /
application/x-nacl : Native Client Executable/nexe
application/pdf : Portable Document Format/pdf
application/x-google-chrome-print-preview-pdf : Portable Document Format/pdf
application/x-shockwave-flash : Adobe Flash movie/swf
...
etc.
If you're using Internet Explorer, then navigator.mimeTypes is not supported unfortunately.
See the link below for confirmation that you cannot get a list of mimetypes from IE: http://www.howtocreate.co.uk/wrongWithIE/?chapter=navigator.plugins
回答2:
Filetypes.js is a project that addresses this issue by making a cross-browser API for getting mime types, descriptions and file extensions.
来源:https://stackoverflow.com/questions/10704489/javascript-get-mime-type-support