admin管理员组

文章数量:1390204

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 e up with the following:

<script type="text/javascript" src=".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?

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 e up with the following:

<script type="text/javascript" src="http://jqueryjs.googlecode./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?

Share Improve this question asked Jul 13, 2011 at 5:25 codacopiacodacopia 2,5119 gold badges41 silver badges59 bronze badges 1
  • I left out the fact that there is a div with the id=print_div that displays the images. – codacopia Commented Jul 13, 2011 at 5:27
Add a ment  | 

1 Answer 1

Reset to default 6

Couldn't you just do:

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

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

本文标签: jqueryCan I Modify this Javascript to Print Images from DivStack Overflow