Upload the same image file twice - Javascript -


i have image uploader in drawing application i've written in javascript. want allow user place multiple of same image on canvas. however, when try upload image that's on canvas, nothing happens , breakpoint in event handler uploader never gets hit. what's going on , how can fix it? thanks!

here's code image handler:

function handleimage(e) { var reader = new filereader(); reader.onload = function(event) {   var img = new image();   img.onload = function() {     img.classname = 'drag';     img.style.left = 0;     img.style.top = 0;     context.drawimage(img, parseint(img.style.left, 10) , parseint(img.style.top, 10));     images.push(img);   }   img.src = event.target.result;  }  reader.readasdataurl(e.target.files[0]);  };  

i tend agree rene pot use same image again (duplicate button), still can't prevent user inserting/loading same image again. i've encountered problem while ago , used bit of code check if image cached (if cached, there no load, hence onload won't fire either).

var img = new image(); img.src = event.target.result;  var insertimage = function() {     img.classname = 'drag';     img.style.left = 0;     img.style.top = 0;     context.drawimage(img, parseint(img.style.left, 10) , parseint(img.style.top, 10));     images.push(img);   }  if(img.complete){    img.onload = insertimage; } else {    insertimage(); } 

hope helps.


Comments