codacopia
codacopia

Reputation: 2501

Can I Modify this Javascript to Print Images from Div?

I have a div in my page layout that I would like to print. I have worked through some sample code on how to do this and come up with the following:

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

function PrintElem(elem)
{
    Popup($(elem).text());
}

function Popup(data) 
{
    var mywindow = window.open('', 'print_div', 'height=400,width=600');
    mywindow.document.write('<html><head><title>Print Window</title>');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');
    mywindow.document.close();
    mywindow.print();
    return true;
}

</script>

Then in the body of the HTML I place the following button:

<input type="button" value="Print Division" onclick="PrintElem('#print_div')" />

This works great for creating a quick print of the text based content on the page, but what I need it to do is print out the images that are being displayed on the page as well. Can I alter this script to do this?

Upvotes: 0

Views: 5851

Answers (1)

James Khoury
James Khoury

Reputation: 22319

Couldn't you just do:

function PrintElem(elem)
{
    Popup($(elem).html());
}

Reference: http://api.jquery.com/html/

Upvotes: 6

Related Questions