Javascript print this page,window,Div,Dialogue box
Posted by Raj
Javascript print this page,window,Div,Dialogue box
In this tutorial, I will explain how to print window using javascript.We are using JavaScript window.print() function to print a window of this page,print dialogue box,print div.One of the most basic JavaScript commands is document.write. This simply prints the specified text to the page.JavaScript programs cannot directly access printers.you need to generate the printable data in a separate browser window.
Example:How do I print JavaScript output?
Javascript print using Hyperlink:-
<a href= "javascript:window.print();"> Print</a>
Javascript print Button:-
//You can call the JavaScript print function .This will automatically open the print dialogue box for the user.
<input type="button" value="Print" onclick="window.print();">
print() is a built-in method of window object.
Suppose I have to enable print feature on a webpage that only prints one of the tables on the page.
Example:Print Table/DIV using javascript
<html>
<head>
<title>Print Table/DIV using javascript</title>
<script language="javascript" type="text/javascript">
function Print()
{
var data = document.getElementById("print_table").innerHTML;
var printdoc=window.open("","","toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=450, height=400, left=100, top=125");
printdoc.document.open();
printdoc.document.write('<html><head><title>Print table using javascript </title></head>');
printdoc.document.write('<body onLoad="self.print();self.close();" >');
printdoc.document.write(data);
printdoc.document.write('</body></html>');
printdoc.print();//You can call the JavaScript print function .This will automatically open the print dialogue box for the user.
printdoc.document.close();
return false;
}
</script>
</head>
<body>
<table id="print_table" style="text-align:left;" width="100%" border="0">
<tr><td align="left"><p>Get row data of html table using jquery</p></td></tr>
</table>
<br /><input type="button" value="Print" onclick="Print();">
</body>
</html>
In this tutorial, I will explain how to print window using javascript.We are using JavaScript window.print() function to print a window of this page,print dialogue box,print div.One of the most basic JavaScript commands is document.write. This simply prints the specified text to the page.JavaScript programs cannot directly access printers.you need to generate the printable data in a separate browser window.
Example:How do I print JavaScript output?
Javascript print using Hyperlink:-
<a href= "javascript:window.print();"> Print</a>
Javascript print Button:-
//You can call the JavaScript print function .This will automatically open the print dialogue box for the user.
<input type="button" value="Print" onclick="window.print();">
print() is a built-in method of window object.
Suppose I have to enable print feature on a webpage that only prints one of the tables on the page.
Example:Print Table/DIV using javascript
<html>
<head>
<title>Print Table/DIV using javascript</title>
<script language="javascript" type="text/javascript">
function Print()
{
var data = document.getElementById("print_table").innerHTML;
var printdoc=window.open("","","toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=450, height=400, left=100, top=125");
printdoc.document.open();
printdoc.document.write('<html><head><title>Print table using javascript </title></head>');
printdoc.document.write('<body onLoad="self.print();self.close();" >');
printdoc.document.write(data);
printdoc.document.write('</body></html>');
printdoc.print();//You can call the JavaScript print function .This will automatically open the print dialogue box for the user.
printdoc.document.close();
return false;
}
</script>
</head>
<body>
<table id="print_table" style="text-align:left;" width="100%" border="0">
<tr><td align="left"><p>Get row data of html table using jquery</p></td></tr>
</table>
<br /><input type="button" value="Print" onclick="Print();">
</body>
</html>
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
JAVASCRIPT,
javascript print,
javascript print button,
javascript print code,
javascript print div,
javascript print window,
javascript printing,
javascript write,
print in javascript,
print this page
.You can leave a response, or trackback from your own site.