如何仅使用javascript确定文档的mime类型?

Fol*_*ken 5 javascript internet-explorer mime-types

我需要确定从服务返回的某些文件的mime类型,我不知道他们的文件扩展名或他们的类型是什么,基本上我们从API检索文档,如:" http:// site. com/getFile/BFD843DFLKXJDF "最后的随机文本是某个文件.

<input type="button" value="Click Me" onClick="alert(document.getElementById('iframeID').contentDocument.contentType);">

<iframe id="iframeID" src="http://site.com/getFile/BFD843DFLKXJDF" width="600" height="600" />
Run Code Online (Sandbox Code Playgroud)

这适用于Firefox,它在警告对话框中返回:pdf文件的"application/pdf".然而,Internet Explorer是我需要定位的主要浏览器,"contentDocument"没有定义(显然我只使用"文档"),但"contentType"也未定义,我不知道IE等价物是什么(谷歌搜索没有产生任何结果).

非常感谢帮助,谢谢.

Luc*_*eis 2

如果http://site.com与您的域不同,您将无法在任何浏览器上访问其数据。这是因为跨站点脚本安全措施。