Can I get an image's file size and mime-type via JavaScript (FireFox/Gecko/Mozilla only)
Can I get an image's file size and mime-type via JavaScript. I am writing开发者_开发问答 a script for inspecting all images in a document. I will run the script in FireFox only so a solution specific to FireFox (undocumented/non-standard/otherwise) is perfectly acceptable. I can use jQuery if necessary.
you can do it through HTTP head request
var request;
request = $.ajax({
type: "HEAD",
url: 'your image url',
success: function () {
alert("Size is " + request.getResponseHeader("Content-Length"));
alert("Type is " + request.getResponseHeader("Content-Type"));
}
});
You could make a HEAD
request with XHR which will tell you the file size, provided these images are on your domain.
精彩评论