javascript - Printing Div with Images -


i working on mvc c# app wherein contents of div composed ajax call retrieves database fields , returned success message javascript. string (a trivial example):

"<div style='background:yellow'>asdf<img src='myfile.jpg'></div>" 

is printed with:

function printdivcontents(contents) {     var printcontents = contents;     var originalcontents = document.body.innerhtml;     document.body.innerhtml = "<div style='margin:10px'>" + printcontents + "</div>";     window.print();     document.body.innerhtml = originalcontents; } 

everything prints in cases, there image in there prints if , if has been loaded previously. print. have tried adding preloading script content string. can use pure javascript, not jquery, , css has inline. options image load? should pause execution wait dom load, assign image hidden div background on calling page, or...?

on page makes initial ajax call, create hidden div such:

<div style="display:none; background:url('myfile.jpg')"></div> 

if file dynamically changed, change background of div prior printing.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -