Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

javascript - Show selected image before upload

In one of my web application I have to implement a image upload. But I need to show the image(s) before upload in my browser . I found the following javascript code and pretty working in all browsers except Safari, IE.

function handleFiles(files) {

for (var i = 0; i < files.length; i++) {
    var file = files[i];

    var imageType = /image.*/;

    if (!file.type.match(imageType)) {


        $('.img_error_con').html("Invalid image file.");
            $('.img_error_con').fadeIn(200);
            return false;


        continue;
    }


    var img=document.getElementById('fake_img');
    img.src = file;
    img.onload = function() {


    };


    var reader = new FileReader();
    reader.onload = (function(aImg) {
        return function(e) {
            aImg.src = e.target.result;
        };
    })(img);
    reader.readAsDataURL(file);
}

}

Please help me to solve the issue in Safari . or any HTML5 method for doing this job ?

Please help Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Welcome to HTML5 non-supported everywhere features...

Safari doesnt support FileReader on windows at least for the moment ,so your script is not going to work just with javascript. I guess IE ( which version ? ) doesnt too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...