Chrome print blank page
It looks like it's attempting to print before the <img>
has loaded, move the call to print inside an event handler for the load event of window
by opening the link as a data URI or Blob, for example
var code = '\
<html>\
<head>\
<title></title>\
<script>\
function printFunction() {\
window.focus();\
window.print();\
window.close();\
}\
window.addEventListener(\'load\', printFunction);\
</script>\
</head>\
<body><img src="'+src+'" width="300"></body>\
</html>';
window.open('data:text/html,' + code, '_blank', 'width=600,height=600');
Don't forget you may need to HTML encode the tags in code
You could probably just listen for load on the <img>
instead, but if you ever do anything more complicated than tring to print a single image you may find it breaks again in future
doc.write('<img onload="printFunction();" src="'+src+'" width="300">');
Where printFunction
is the print function for all browsers
how to avoid extra blank page at end while printing?
You could maybe add
.print:last-child {
page-break-after: auto;
}
so the last print
element will not get the extra page break.
Do note that the :last-child selector is not supported in IE8, if you're targetting that wretch of a browser.
element print preview is blank and prints blank pages in Google Chrome
Since the <script></script>
tags are breaking the code, try using this line :
mywindow.document.write('<scr'+'ipt type="text/javascript">$(window).load(function() { window.print(); window.close(); });</scr'+'ipt>')
And without jQuery :
mywindow.document.write('<scr'+'ipt type="text/javascript">function PrintPage() { window.print(); window.close(); } window.onload = PrintPage;</scr'+'ipt>');
Windows.print() creating a blank page before pages
Although I didn't solve the problem, I fixed it by having the page open in a new tab so I can avoid a redirect altogether.
windows.print results in empty page
To anyone having the same problem: I couldn't figure out what was causing it, but I could get it done using the window.frame
approach elaborated in this answer.
Related Topics
How to Change Background Opacity When Bootstrap Modal Is Open
How to Change Height in Mat-Form-Field
How to Avoid the Setstate()/Render() Endless Loop When Passing Data from Child to Parent
Pdf Blob - Pop Up Window Not Showing Content
How to Export Json Data to Excel File Using JavaScript
Angular Load Async Data Before Component Initialization
Html5 and JavaScript to Play Videos Only When Visible
Javascript to Download a File from Amazon S3 Bucket
How to Redirect to Another Page Using Angularjs
Disable Right-Clicking in Html5 Video
Regular Expression Which Allow Only Characters or Space
Use Localstorage Variables in PHP
How to Attach Multiple Images in a Embed
Vuejs Set Active Class, When One Li Element Clicked in V-For Loop
Onclick Table Row With Onclick Button and Bootstrap Modal Inside
Assigning Id to All Elements of a Page in Angular Automatically