简体   繁体   中英

How to keep page design when I print it new tab Jquery?

I use this function to make print

     function printContent(el,tble,img) {         
                var printcontent = document.getElementById(el).innerHTML
                   +" <div class='row'><span class='glyphicon glyphicon-tasks'></span><b></b></div>"
                   + document.getElementById(tble).innerHTML
                   + document.getElementById(img).innerHTML;

                var w = window.open();   
               $(w.document.body).html(printcontent);
                w.print();
}

this works fine for me but the problem is it didn't contain the same page design and the print page has no design

please help

You should use a link in the head of your page:

<link rel="stylesheet" type="text/css" media="print" href="style.css">

Note the media attribute.

Edit:

var bodyContent = document.getElementById(el).innerHTML
                   +" <div class='row'><span class='glyphicon glyphicon-tasks'></span><b></b></div>"
                   + document.getElementById(tble).innerHTML
                   + document.getElementById(img).innerHTML;

var windowHTML = '<html><head><title>Print page</title><link rel="stylesheet" type="text/css" media="print" href="style.css"></head><body>' + bodyContent + '</body>';

var w = window.open();   
w.document.write(windowHTML);
w.print();

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