对于一款允许在浏览器中预览文档的网络应用,我想检查用户的浏览器是否支持当前文档 MIME 类型的预览。
是否有基于 JavaScript 的方法来将当前 MIME 类型与浏览器支持的类型进行匹配呢?
谢谢!
是否有基于 JavaScript 的方法来将当前 MIME 类型与浏览器支持的类型进行匹配呢?
谢谢!
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);
};
application/pdf
。 - marcel $.ajax({
type: "GET",
url: 'http://..../thing.pdf',
success: function (output, status, xhr) {
alert("done!"+ xhr.getAllResponseHeaders());
alert("done!"+ xhr.getResponseHeader("Content-Type"));
}
});
如果您定义了特定文档类型所需的插件,则可以尝试查看所需的插件是否存在。应该至少在Firefox和Chrome上可用。 window.navigator.plugins
(注意:由于技术术语等原因,翻译可能不是唯一正确的表达方式。)