简体   繁体   中英

window.print() show blank page (no content at all)

i want to print the whole webpage (html including css) im using window.print() on button onClick. when click the button it shows the print preview but doesnt show any content. the page was blank on print preview. By the way i am using chrome version 73.0.3683.86

I already try javascript function but didnt work at all.not even print preview.

<input type="button" class="btn btn-primary" onClick="window.print()" value="print"/>

you spelt "onclick" as "onClick", there is no need for the camelCase. Try the code below

<input type="button" class="btn btn-primary" onclick="window.print()" value="print"/>

I've tries various solutions, only this helped me:

HTML:

<a onclick="printPage();return false;" href="#">Print details</a>

JS:

<script>
    function printPage(){
        var printHtml = window.open('', 'PRINT', '');
        printHtml.document.write('<html><head>');
        printHtml.document.write(document.getElementById("printme").innerHTML);
        printHtml.document.write('</body></html>');
        printHtml.document.close(); 
        printHtml.focus();
        printHtml.print();
        printHtml.close();
        return true;
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM