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

问题描述 投票:14回答:4

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

是否有基于Java的方法将当前的mime类型与浏览器支持的类型进行匹配?

谢谢!

javascript mime-types browser-support
4个回答
5
投票

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

这里是解gistjsfiddle

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);
};

3
投票

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

 $.ajax({
    type: "GET",
    url: 'http://..../thing.pdf',
    success: function (output, status, xhr) {
      alert("done!"+ xhr.getAllResponseHeaders());
      alert("done!"+ xhr.getResponseHeader("Content-Type"));
    }
  });

1
投票

在此问题中,我认为存在相同的问题,请尝试检查一下

Check if a browser supports a specific MIME type?


0
投票

如果您定义了特定文档类型所需的插件,则可以尝试查看是否存在所需的插件。至少应在Firefox和Chrome上运行。window.navigator.plugins

© www.soinside.com 2019 - 2024. All rights reserved.