image,onload事件不能在chrome中工作 [英] image,onload event not working in chrome

查看:627
本文介绍了image,onload事件不能在chrome中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用html5来创建拖放图片上传功能。这工作伟大的我在firefox,但在chrome的image onload事件只有第一次发射。如果我只拖动多个图像的第一个作品,如果我拖动一秒钟失败。我相信问题是与image onload。

I'm using html5 to create drag and drop image upload functionality. This works great for me in firefox but in chrome the image onload event only fires the first time. If I drag multiple images in only the first works and if I drag a second in it fails. I believe the problem is with the image onload.

这里是我的代码工作方式我已删除不相关的部分:

here is the way my code works I have removed the irrelevant sections:

            var img = document.createElement("img");
            var reader = new FileReader();
            var canvas = document.createElement("canvas");
            var canvasData;
            var ctx = canvas.getContext("2d");
            var myFiles;
            var i = 0; 


                 reader.onload = (function (aImg)
                    { 
                        return function (e)
                        {
                            aImg.src = e.target.result;
                        };
                    })(img);

        img.onload = function (){

        //resizes image 
        //draws it to the canvas
        //posts to server

        i++;
        if(i < myFiles.length){
        processNext(i);
                            }
        }



    function processNext(filei) {

         var file = myFiles[filei];

            img.file = file;

            reader.readAsDataURL(file);


        }

i = 0;
myFiles = files;
processNext(0);

有没有人知道为什么这在firefox中有效,但不是chrome?

Does anyone know why this works in firefox but not chrome?

推荐答案

铬跟踪器的说明:


这不是一个错误。 WebKit只是更严格。您必须在替换之前实例化一个新的Image()对象...

This is not a bug. WebKit is just more strict. You must instantiate a new Image() object before the replacement...

source: http://code.google.com/p/chromium/issues/detail?id=7731#c12 < a>

source: http://code.google.com/p/chromium/issues/detail?id=7731#c12

这篇关于image,onload事件不能在chrome中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆