17

对于允许在浏览器中预览文档的 Web 应用程序,我想检查用户的浏览器是否支持预览当前文档的 mime 类型。

是否有基于 Javascript 的方法来匹配当前的 mime 类型与浏览器支持的类型?

谢谢!

4

4 回答 4

4

在最近的浏览器中有 navigatior.plugins 类似数组的对象。您可以检查每个插件的 mime 类型。

这是解决方案要点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);
};
于 2014-09-24T08:59:00.233 回答
2

您可以进行 AJAX 调用并检查 mimetype 的响应标头。

 $.ajax({
    type: "GET",
    url: 'http://..../thing.pdf',
    success: function (output, status, xhr) {
      alert("done!"+ xhr.getAllResponseHeaders());
      alert("done!"+ xhr.getResponseHeader("Content-Type"));
    }
  });
于 2013-02-12T15:02:53.117 回答
1

在这个问题中,我认为有同样的问题,尝试检查一下

检查浏览器是否支持特定的 MIME 类型?

于 2013-02-12T15:04:44.953 回答
0

如果您定义了特定文档类型需要哪个插件,那么您可以尝试查看是否存在需要的插件。至少应该在 Firefox 和 Chrome 上工作。 window.navigator.plugins

于 2013-02-12T15:04:08.363 回答