开发者

Detect mime type of an image via Javascript

i am detecting images on my webpage with javascript document.images function which returns an rray of images. Is there any way to 开发者_Go百科get the mime type of the image from this since i am not using any extension names on images which are loading?


I don't think this is possible, apart from requesting the image again in jQuery and trying to use a MIME type check on the data. (You might be able to send a HEAD request and get whatever Content-type was returned)


According with other answers, I got pretty surprised to find out it was apparently not possible without requesting the image again. (??? That seems weird to me but oh well…)

Another hacky-but-might-be-enough-for-your-use-case-solution that comes in my mind would be to:

Parse the img.src in an attempt of guessing the file type.

  • "Guessing?" you may ask…
  • Yes because the extension might not be included in the src or could be misleading.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜