What is jPrintArea?
jPrintArea is a small jquery plugin to print only contents of a specified element. P.S. This is my first jQuery Plugin
Update: Replaced the annoying alert box with wait() function.
Usage
$.jPrintArea(container); // $.jPrintArea('#tabularData');
Source
jQuery.jPrintArea=function(el)
{
var iframe=document.createElement('IFRAME');
var doc=null;
$(iframe).attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
for(var i=0;i<links.length;i++)
if(links[i].rel.toLowerCase()=='stylesheet')
doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
doc.write('<div class="'+$(el).attr("class")+'">'+$(el).html()+'</div>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
//alert('Printing...'); thanks alex
wait(1);
document.body.removeChild(iframe);
}
Example
| Name | Major | Sex | English | Japanese | Calculus | Geometry |
|---|---|---|---|---|---|---|
| Student01 | Languages | male | 80 | 70 | 75 | 80 |
| Student02 | Mathematics | male | 90 | 88 | 100 | 90 |
| Student03 | Languages | female | 85 | 95 | 80 | 85 |
| Student04 | Languages | male | 60 | 55 | 100 | 100 |
| Student05 | Languages | female | 68 | 80 | 95 | 80 |
| Student06 | Mathematics | male | 100 | 99 | 100 | 90 |
| Student07 | Mathematics | male | 85 | 68 | 90 | 90 |
| Student08 | Languages | male | 100 | 90 | 90 | 85 |
| Student09 | Mathematics | male | 80 | 50 | 65 | 75 |
| Student10 | Languages | male | 85 | 100 | 100 | 90 |
| Student11 | Languages | male | 86 | 85 | 100 | 100 |
| Student12 | Mathematics | female | 100 | 75 | 70 | 85 |
Feedback / Comments / Suggestions