Here is the actual code:

"function(file,dataUrl){var date = new Date(); var path = window.location.host+'/frontend/web/image/page/'+date.getFullYear()+'/'+(1+date.getMonth())+'/'+file.name;var img='<img src=\"'+path+'\" />'; document.getElementById('forIMG').appendChild(img[0]);}" 

Quotation marks at the beginning and end of the code are actually needed because I use js in the php plugin, which I broke in lines.

 function(file,dataUrl){ var date = new Date(); var path = window.location.host+'/frontend/web/image/page/'+date.getFullYear()+'/'+(1+date.getMonth())+'/'+file.name; var img='<img src=\"'+path+'\" />'; document.getElementById('forIMG').appendChild(img[0]);} 

tried and so

 function(file,dataUrl){ var date = new Date(); var path = window.location.host+'/frontend/web/image/page/'+date.getFullYear()+'/'+(1+date.getMonth())+'/'+file.name; var img='<img src=\"'+path+'\" />'; document.getElementById('forIMG').appendChild(img)[0];} 

The effect is the same.

    2 answers 2

    Try this

     function(file,dataUrl){ var date = new Date(); var path = window.location.host+'/frontend/web/image/page/'+date.getFullYear()+'/'+(1+date.getMonth())+'/'+file.name; var img = document.createElement('img'); img.src = path; document.getElementById('forIMG').appendChild(img)[0]; } 

    • [0] - not needed - Grundy

    Here is the string going

     var img='<img src=\"'+path+'\" />'; 

    Then the first character img[0] is taken from it, or an attempt is made to insert it as a string.

    Instead, you can create the img element itself, using the createElement function , assign it to the created src element, and add it, for example

     var img = document.createElement('img'); img.src = path; document.getElementById('forIMG').appendChild(img)