Home > Javascript > Print content of a element

Print content of a element

November 25, 2009 Leave a comment Go to comments

If you want to print content of a html element, with the help of javascript you can do this.  You need to call  this function and pass a argument ( element id ). Take a look of this function.

<script type=”text/javascript”>
function printSelection(node){
var content=node.innerHTML
var pwin=window.open(”,’print_content’,’width=12800,height=1000, scrollbars=1′);
pwin.document.open();
pwin.document.write(‘<html><body onload=”window.print()”>’+content+'</body></html>’);
pwin.document.close();
//setTimeout(function(){pwin.close();},1000);
}
</script>

Now time to call this function. I called this function in a hyperlink like this.
<a href=”” onclick=”printSelection(document.getElementById(‘foo’));return false”>Print</a>

When you click on “Print” then print dialog appears give print command and enjoy this script.

Click here

Advertisements
Categories: Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: