Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  55] [ 3]  / answers: 1 / hits: 117936  / 11 Years ago, wed, november 20, 2013, 12:00:00

So, lets say I got a simple form inside a page like this:



<form style=text-align:center;>
<p> STUFF </p>
</form>


I wanna add a button so when the user clicks on it the browser's Print dialog shows up, how can I do that?



Edit: I wanna print the form, not the page.


More From » html

 Answers
18

Print the whole page


Try adding a button that calls window.print()


<input type="button" value="Print this page" onClick="window.print()">

Print a specific portion/container in a page


<div id="print-content">
<form>

<input type="button" onclick="printDiv('print-content')" value="print a div!"/>
</form>
</div>

then in the HTML file, add this script code


<script type="text/javascript">
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
w=window.open();
w.document.write(printContents);
w.print();
w.close();
}
</script>

Refer Print <div id="printarea"></div> only?


[#74161] Tuesday, November 19, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
estefanib

Total Points: 508
Total Questions: 104
Total Answers: 83

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;