Reputation: 3666
I would like to print only certain part of my page. My sample code follows:
<%@ page contentType="text/html;charset=ISO-8859-1" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Insert title here</title>
</head>
<body>
<div class="body">
Blah... blah...
</div>
<div class="printable">
contents goes here...
</div>
</body>
</html>
I need to print the contents of <div class="printable"></div>
. Is it possible to do this using jQuery? Should I write this solution, or is there a plugin that would help solve this problem?
Upvotes: 6
Views: 13133
Reputation: 50167
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
body * { display: none; }
.printable { display: block; }
window.print();
Upvotes: 4
Reputation: 3666
i haven't get any good solution from stackoverflow so i am posting answer myself..
<%@ page contentType="text/html;charset=ISO-8859-1" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Insert title here</title>
<script type="text/javascript">
printDivCSS = new String ('<link href="myprintstyle.css" rel="stylesheet" type="text/css">')
function printDiv(divId) {
window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById(divId).innerHTML
window.frames["print_frame"].window.focus()
window.frames["print_frame"].window.print()
}
</head>
<body>
<div class="body">
Bla h......... blah...
</div>
<div class="printable">
contents goes here.........
</div>
<b></b> <a href=javascript:printDiv('printable')>Print This Div</a><br>
refer: How do I print part of a rendered HTML page in JavaScript?
Upvotes: 2