javascript - How to read the image type from an URL? -


i encountered strange:

enter image description here

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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -