Print specific part of webpage
You can use simple JavaScript to print a specific div from a page.
var prtContent = document.getElementById("your div id");
var WinPrint = window.open('', '', 'left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
How do I print part of a rendered HTML page in JavaScript?
I would go about it somewhat like this:
<html>
<head>
<title>Print Test Page</title>
<script>
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();
}
</script>
</head>
<body>
<h1><b><center>This is a test page for printing</center></b><hr color=#00cc00 width=95%></h1>
<b>Div 1:</b> <a href="javascript:printDiv('div1')">Print</a><br>
<div id="div1">This is the div1's print output</div>
<br><br>
<b>Div 2:</b> <a href="javascript:printDiv('div2')">Print</a><br>
<div id="div2">This is the div2's print output</div>
<br><br>
<b>Div 3:</b> <a href="javascript:printDiv('div3')">Print</a><br>
<div id="div3">This is the div3's print output</div>
<iframe name="print_frame" width="0" height="0" frameborder="0" src="about:blank"></iframe>
</body>
</html>
how to print specific part of webpage using node-jade template engine
Solution
After searching and reading lot of solutions on so, i found that it is pretty simple and nothing to do with jade or javascript and done using css.
Here is how:
Solution on SO
Thanks Stack overflow.
How to print some specific part of a page via window.print()
Use css to hide elements you don't want to print:
@media print {
.control-group {
display: none;
}
}
PHP print specific part of page
Use javascript's window.print()
in normal cases where javascript is enabled, and simply add a <noscript>
tag to tell the user that they have to enable javascript in order to print.
Something like this:
<noscript>Please enable javascript in order to print the page.</noscript>
How can I print a certain block/part of a web page?
Use css, with the media = print option.
Like:
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
The blocks you don't want printed can set display:none.
Related Topics
JavaScript Function Name Cannot Set as Click
Can Someone Explain This 'Double Negative' Trick
How to Load Images Dynamically (Or Lazily) When Users Scrolls Them into View
Error: Failed to Execute 'Appendchild' on 'Node': Parameter 1 Is Not of Type 'Node'
How to Change CSS :Root Color Variables in JavaScript
Jquery $("#Radiobutton").Change(...) Not Firing During De-Selection
How to Select Element That Does Not Have Specific Class
Chrome Autofill/Autocomplete No Value for Password
How to Add and Remove Classes in JavaScript Without Jquery
How to Detect Element Being Added/Removed from Dom Element
Phonegap Inappbrowser Display PDF 2.7.0
Trigger Standard HTML5 Validation (Form) Without Using Submit Button
Angularjs Does Not Load Scripts Within Ng-View
Jquery Mobile - $.Mobile.Changepage Not Loading External .Js Files
How to Read Xml File Contents in Jquery and Display in HTML Elements
Property 'Submit' of Object #<Htmlformelement> Is Not a Function