2

I have a problem with this code:

function handleFileSelect(evt) {
   evt.stopPropagation();
   evt.preventDefault(); // stop default

   console.log('ejecutado handleFileSelects')

   var divOrigen = evt.target.parentNode; //get the div of the input
   var divDestino = $(divOrigen).find('img'); //get the div for preview the img
   var inputDestino = $(divOrigen).find('input[type="file"]'); // the input file 
   var files = evt.target.files; //get files in array

   if (files.length) {
      for (var i = 0, f; f = files[i]; i++) {
         if (!f.type.match('image.*')) {
            continue;
         }
         var reader = new FileReader();
         reader.onload = (function (theFile) {
            return function (e) {
               $(divDestino).attr('src', e.target.result); //read files content to preview in div
            };
         })(f);
         reader.readAsDataURL(f);
      }
      $(inputDestino).popover('destroy');
   } else {
      evt.stopPropagation();
      evt.preventDefault();
      $(inputDestino).popover('show');
      console.log('files is empty');
      $(divDestino).attr('src', '/images/index/publicacion/dragAndDropHere.png');
   }
}

This code changes the background of a div. The purpose of the div is to preview the image of the input file. In Opera, Firefox, Internet Explorer and Safari it works fine, but when I try it on my Android tablet, nothing happens. Is there a tool similar to Firebug for Android? Or any framework that I can use for Android tablets?

1 Answer 1

1

Try removing the first / from the image source, so instead of

$(divDestino).attr('src', '/images/index/publicacion/dragAndDropHere.png');

you have

$(divDestino).attr('src', 'images/index/publicacion/dragAndDropHere.png');
Sign up to request clarification or add additional context in comments.

1 Comment

dragAndDropHere.png is an image that appears by default in the div indicating the zone to drop the image ... this is not the error...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.