javascript - window.open with blank url wait for dynamic html to load then print -


<script>    var win = window.open();    win.document.body.innerhtml = "this html want print";    win.onload = function () { win.print(); } </script> 

everything works print, how wait until page loads dynamic html blank url, print?

i don't think there way it, user below me onload wont fire because window opened page loaded. i'm trying load entire page first print. script posted doesn't this.

martin, using code:

<script> var win = window.open(); win.document.body.innerhtml = "<img src='https://upload.wikimedia.org/wikipedia/commons/2/24/willaerts_adam_the_embarkation_of_the_elector_palantine_oil_canvas-huge.jpg'/>"; win.print(); </script> 

in chrome prints blank page.

edit:

martin, onload img attribute did trick. heres did modify script:

<script>  var win = window.open();  var html = "this test html <br><img src='https://upload.wikimedia.org/wikipedia/commons/2/24/willaerts_adam_the_embarkation_of_the_elector_palantine_oil_canvas-huge.jpg'/>";  html = html.replace("<img ","<img onload='window.print();' ");  win.document.body.innerhtml = html; </script> 

so img tags add onload=window.print. 1 of them needs onload (i'm pretty sure....). give more information, in scenario variable html infinite number of images, random text,tables, etc. anything. thank martin having patience re-read thread , reply.

jeff, make work image, i'm pasting example below. however, depending on how final page perhaps more generic solution needed. page more complex?

<script>      var win = window.open();      win.document.body.innerhtml = "<img src='https://upload.wikimedia.org/wikipedia/commons/2/24/willaerts_adam_the_embarkation_of_the_elector_palantine_oil_canvas-huge.jpg' onload='window.print();'/>"; </script> 

this works (without images):

<script>     var win = window.open();     win.document.body.innerhtml = "this html want print";     win.print(); </script> 

i don't think need onload you're not loading page, won't fire.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -