1) Print Window On Load:
using page load we can print easily print the page:
<script type=”text/javascript”>
window.onload = function() { window.print(); }
</script>
using page load we can print easily print the page:
<script type=”text/javascript”>
window.onload = function() { window.print(); }
</script>
2) Ater clicking the link also we can print the page:
<a href=”javascript:window.print()”>Print This Page</a>
<a href=”javascript:window.print()”>Print This Page</a>
3) Print Div Content Using JavaScript
instead of printing an entire page we can print a section from the page (based on DIV ID).
instead of printing an entire page we can print a section from the page (based on DIV ID).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Print Page Example</title><script language="javascript" type="text/javascript">function printPage(divID) {//Get the HTML of divvar divElements = document.getElementById(divID).innerHTML;//Get the HTML of whole pagevar oldPage = document.body.innerHTML;//Reset the page's HTML with div's HTML onlydocument.body.innerHTML ="<html><head><title></title></head><body>" +divElements + "</body>";//Print Pagewindow.print();//Restore orignal HTMLdocument.body.innerHTML = oldPage;}</script></head><body><form id="frmPrint"><div id="printSection" style="width: 100%; background-color: Green; height: 200px">Print me TheBlogReaders.com</div><div id="noprintSection" style="width: 100%; background-color: Yellow; height: 200px">THIS SECTION NOT PRINTING</div><input type="button" value="Print First Section" onclick="javascript:printPage('printSection')" /></form></body></html> |
(22)
No comments:
Post a Comment