Я пытаюсь загрузить изображение динамически с помощью функции document.write
. Пожалуйста, найдите код ниже. Изображение иногда загружается, а иногда не отображается.
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>'+"Contract Approval Form"+'</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<div id="headerLogo"></div>');
mywindow.document.write('<div id="watermarkDiv"></div>');
mywindow.document.write('<div style="margin-top:50px;" id="content">' +printContent+ '</div>');
var img = mywindow.document.createElement('img');
img.setAttribute('src', 'mylogo.png');
mywindow.document.getElementById("headerLogo").appendChild(img);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();