1

How to get image width , height, and file type using javascript On IE7, 8 , After select file ?

I try this but not work on Ie7 , 8.

var _URL = window.URL || window.webkitURL;
$("#myFile").change(function (e) {
    var file, img;
    if ((file = this.files[0])) {
        img = new Image();
        img.onload = function () {
            alert(this.width + " " + this.height);
        };
        img.src = _URL.createObjectURL(file);
    }
});
robert dewo
  • 33
  • 1
  • 5
  • 1
    I believe you need to actually add the image to the dom for this to do anything. – pquest Dec 12 '14 at 13:35
  • @pquest: Without File API you cannot read its URL and data, so .. how? – Liglo App Dec 12 '14 at 13:43
  • Add the image to a dom element with display:none or positioned off screen, you can then get the data from it, then remove the temp image from the dom – atmd Dec 12 '14 at 13:43
  • I believe you will have to add the image underneath something instead of using display:none as I think dom elements return a dimension of 0x0 when they are set this way, but that is otherwise exactly what I was suggesting. – pquest Dec 12 '14 at 13:49

1 Answers1

0

It will never work, because it is possible only with HTML5. See this.

Liglo App
  • 3,719
  • 4
  • 30
  • 54