javascript - Print Preview Is Blank After adding External Stylesheet reference in print html content -
i want print div content of page.what retrieve contents of div using js , pass new window obj on call .print(). text contents , images displayed such. when add line retrieved div contents
<link href="myprintstyle.css" rel="stylesheet" type="text/css">
the print preview blank. tried adding other stylesheets well,same result. whatever style sheet reference add print html contents,same result -blank preview page. here js code print page contents.
var printdivcss = new string ('<link href="myprintstyle.css" rel="stylesheet" type="text/css">'); function popup(htmldata) { var mywindow = window.open('test', 'echallanreceipt', 'height=800,width=800,top=20;left=20'); var str ="<html><head><title>test</title>"; str+= "</head><body>"+ printdivcss + htmldata+"</body></html>"; mywindow.document.write(str); mywindow.document.close(); // necessary ie >= 10 mywindow.focus(); // necessary ie >= 10 mywindow.print(); mywindow.close(); return false; }
please suggest fix. want style print content. browser: chrome
the same code working in mozilla. in chrome facing issue.
i know old question having problem here solution.
it showing blank page because document not finished loading yet. fix add mywindow.print()
in timeout
.
var printdivcss = new string ('<link href="myprintstyle.css" rel="stylesheet" type="text/css">'); function popup(htmldata) { var mywindow = window.open('test', 'echallanreceipt', 'height=800,width=800,top=20;left=20'); var str ="<html><head><title>test</title>"; str+= "</head><body>"+ printdivcss + htmldata+"</body></html>"; mywindow.document.write(str); mywindow.document.close(); // necessary ie >= 10 $( mywindow.document).ready(function(){ //set timeout longer if have many resources load settimeout(function(){ mywindow.focus(); mywindow.print(); },1000); return false; }
Comments
Post a Comment