Javascript get MIME type support

こ雲淡風輕ζ 提交于 2019-12-24 00:22:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!