javascript - How to read the image type from an URL? -
i encountered strange:
as see second last picture has jpg format it's being displayed png
type. (this network panel in chrome.)
how can png
file type javascript? (how can it's mime type)?
you check content-type
response header. appropriate value listed in chrome network debugger. alternatively, can on 1 of many lists on internet.
assuming using jquery
$.ajax({ url: "[image url]", success: function(response, status, xhr){ var contenttype = xhr.getresponseheader("content-type") || ""; if (contenttype === "image/jpeg") { // jpg } if (contenttype === "image/png") { // png } } });
if using plain javascript use xmlhttprequest.getresponseheader()
in stead.
Comments
Post a Comment