开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜