In my HTML document, there is a image
<img src="https://www.gravatar.com/avatar/1d9c87a4d5cbcae4c76e867cb6861fa0?s=48&d=identicon&r=PG&f=1"/>
When open this document in browser, E.g. Chrome, we can find the Content-Type
of this image is "image/png"
in Chrome Developer Tools -> Network tab according to the HTTP response headers.
How can I get the Content-Type
using JavaScript after the image loading.
More specifically, what I need is a function like below.
/**
* @param {HTMLImageElement} img
* @return {String} the content type, e.g. "image/png", "image/svg+xml"
*/
getImgContentType(img) {
// TODO
}
console.log
and find out yourself?<img>
tag im HTML or via JS?HEAD
to the url of the image.HEAD
to the URL of the image"?