10

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

2
  • 3
    Just curious - why do you need that information in javascript? Commented May 6, 2010 at 19:47
  • @SripathiKrishnan Detecting gifs and replacing them with placeholders comes into mind … Commented Jul 22, 2014 at 18:49

2 Answers 2

4

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)

Sign up to request clarification or add additional context in comments.

1 Comment

an AJAX HEAD request is the only thing I too can think of.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.