Click here to Skip to main content
14,091,011 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 4 Apr 2013
Licenced CPOL

How to Print a Particular Portion of a Webpage?

, 4 Apr 2013
Rate this:
Please Sign up or sign in to vote.
How to print a particular portion of a webpage?


Here I am going to demonstrate “how to print a particular portion of webpage?”. We use Window.Print() JavaScript in order to print data displayed on web-page. But there may be a case when I didn’t need to print the whole page or just required to print one small portion of page instead of the whole page, in those scenarios, Window.print() won’t work. So what should we do in such a situation? Here is the answer.

Inside the Code

We can print web document through JavaScript, so definitely we’ll write some JavaScript to print portion of web page. Here is the script:

function CallPrint(strid) {
    var prtContent = document.getElementById(strid);
    var WinPrint ='', '', 'letf=0,top=0,width=1,height=1,
    prtContent.innerHTML = strOldOne;

Now, how to use this JavaScript? For that, create a <div /> element and assign unique id to it (i.e. <div ID=”divPrint”). Now put your HTML content between this <div />.

For example, if I want to print Item information which are displays on grid like:

<asp:DataGrid Id="grdItem" runat=""server">

Put this whole HTML content between <div/> tag. Now in the onClientClick event of button, call JavaScript function like:


This completes your printing.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Himanshu Manjarawala
Team Leader Automation Anywhere Inc.
India India
I am Himanshu Manjarawala, Garduate in Computer Science and MCA From Veer Narmad South Gujarat University, Surat Gijarat India. Currently working as Sr. Software Developer in Automation Anywhere Softwares Pvt. Ltd. Vadodara, Gujarat

You may also be interested in...

Comments and Discussions

QuestionWhat about css? Pin
Bernhard Hiller16-Apr-13 4:38
memberBernhard Hiller16-Apr-13 4:38 
QuestionRe: What about css? Pin
Himanshu Manjarawala30-May-13 18:18
memberHimanshu Manjarawala30-May-13 18:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190518.1 | Last Updated 5 Apr 2013
Article Copyright 2013 by Himanshu Manjarawala
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid