PrintingSee also Printing an iframeOpen and write data to popup, print popup contents, close popup Although there is not a simple command that allows the printing
of part of a document there are a couple of methods that can be
used. The text to be printed is contained in a div <DIV id="print_div1" style="border:1px solid #000000">
Only the contents of this div are printed.
</DIV>
I have used a border to highlight the printable content.
The id of the div is passed to the function. <a href="#null" onclick="printContent('print_div1')">Click to print div 1</a> On clicking the link the following sequence of events happens.
Other areas of a page can be printed simply by defining another div and link <DIV id="print_div2">
A second div containing text to be printed.
</DIV>
Ditto, ditto and ditto <a href="#null" onclick="printContent('print_div2')">Click to print div 2</a> Just add the below script anywhere in your html document. <script type="text/javascript"> <!-- function printContent(id){ str=document.getElementById(id).innerHTML newwin=window.open('','printwin','left=100,top=100,width=400,height=400') newwin.document.write('<HTML>\n<HEAD>\n') newwin.document.write('<TITLE>Print Page</TITLE>\n') newwin.document.write('<script>\n') newwin.document.write('function chkstate(){\n') newwin.document.write('if(document.readyState=="complete"){\n') newwin.document.write('window.close()\n') newwin.document.write('}\n') newwin.document.write('else{\n') newwin.document.write('setTimeout("chkstate()",2000)\n') newwin.document.write('}\n') newwin.document.write('}\n') newwin.document.write('function print_win(){\n') newwin.document.write('window.print();\n') newwin.document.write('chkstate();\n') newwin.document.write('}\n') newwin.document.write('<\/script>\n') newwin.document.write('</HEAD>\n') newwin.document.write('<BODY onload="print_win()">\n') newwin.document.write(str) newwin.document.write('</BODY>\n') newwin.document.write('</HTML>\n') newwin.document.close() } //--> </script>
|