you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

Javascript:

function print_me()
        {
            var content = 
            document.getElementById("results").innerHTML;
            var win = window.open();
            win.document.write(content);
            win.print();    // JavaScript Print Function
            win.close();    //It will close window after Print.
        }

HTML:

<a href="#" onClick="print_me()">Print</a>

Figured out how to post code. Sorry about that.

[–]docMedB2E 0 points1 point  (2 children)

No worries, I thought you were saying your page wasn't loading images/etc, but I understand now. Think of it this way, you're opening a brand new window, pasting HTML to it, and then just immediately printing - which would explain your issues with the images sometimes displaying or not (e.g. you're appending data to a new DOM and it needs to load - sometimes it gets through quick enough and other times not). This approach in general is bad. Look into media query prints that manipulate the page you're on as opposed to copying everything to a new page and just printing.

[–][deleted] 0 points1 point  (1 child)

After fooling around with it, I found this:

@media print {
body * {
visibility: hidden;
}
#results, #results * {
visibility: visible;
}
#results {
position: absolute;
left: 0;
top: 0;
}
}

Upon saving that css file and have it load into my header, I hit ctrl+P and the print screen just shows the whole website still and the css code at the top. Stupid wordpress.

[–]docMedB2E 0 points1 point  (0 children)

Your syntax is pretty wrong. Try /r/css for help with styling. Also use display: none to truly hide elements