Tuesday, June 7, 2011

Javascript Print, Print command and Print Preview using JavaScript, Custom JavaScript Web page Print, Javascript print Tutorial

when we create a website for every article of website we need to implement Print command to our Site Articles because using browsers inbuilt command we get whole print page.

which cause extra content and element to print.

So I am Providing the Simple Javascript tutorial to get print of page.

Define this javascript function to your HTML's Head tag.

<script language="javascript" type="text/javascript">

function CallPrint( strid,prt_head )
    var prtContent = document.getElementById( strid );
    var WinPrint = window.open('', '', 'left=30,top=0,width=600,height=600,toolbar=1,scrollbars=1,status=0');
var ss='<table style="text-align:justify;"><tr><td class="normaltextwhite" bgcolor="#F36F22" style="color:#fff; padding-left:10px;">'+ prt_head + '</td></tr><tr><td>' + prtContent.innerHTML + '</td></tr></table>';
   WinPrint.document.write( ss );

Now call the javascipt function using two argument.
  1. First argument is for Content of which print.
  2. Second argument is for Heading of page.

<a class="letter" href="javascript:CallPrint('inner_content','Corporate Overview');">

No comments: