Print the contents of div with css

Asked

Viewed 933 times

1

I got it with the help of Stackoverflow assemble a script for printing a document, now I’m with a second problem, the script opens the print page without formatting the css. I saw an example right here but could not change according to what I need, I saw it here:

Example of css being loaded

In the example css is being loaded by script, but in my example I have this:

document.getElementById('btn').onclick = function() {   
    var conteudo = document.getElementById('conteudo').innerHTML,
    impressao = window.open('about:blank');
    impressao.document.write(conteudo);
    impressao.window.print();
    impressao.window.close();
};

How can I load css in my example?

  • And where is the CSS? You want to add it to a popup open? It’s a CSS code block or a file?

  • Hello @Kaduamaral, css is called on my page being inserted by this command: <link href=".. /_comp/externals/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

  • That code <link href="..."> is within the element div#conteudo? Example

  • No, it is called in head, the example you passed runs, shows the preview formatted but the printing is not configured.

  • 1

    Well, then, keep in mind that impressao.document is a new document (a totally different and independent website for the browser). Place a copy of the code <link href="..."> within the element div#conteudo or try something like impressao.document.write('<link href="...">' + conteudo);.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.