Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,151,334 members, 7,811,975 topics. Date: Monday, 29 April 2024 at 03:37 AM |
Nairaland Forum / Science/Technology / Programming / How To Code The Printing Of A Particular/desire Space On A Web Page (879 Views)
How To Code Your Own Personal Assistant In Python / Stunning Web Page Wit Asp.net / Retrieving/selecting A Particular Number Of Random Rows From A Database Table (2) (3) (4)
How To Code The Printing Of A Particular/desire Space On A Web Page by popin5(m): 10:00am On Nov 18, 2009 |
i am doing a web application using php and another using C sharp/ASPX, i want to create a button to print d content of the a particular space [larger not all ] of page. am i to make for this space a frame or use CSS. And what function should i call to make the printing possible. i will appreciate the process for both the php and aspx concepts |
Re: How To Code The Printing Of A Particular/desire Space On A Web Page by yawatide(f): 11:16am On Nov 18, 2009 |
your question is not clear but if I do understand you, you can: 1) Declare a style sheet with media type of print 2) In this sheet, set any portion of the page you don't want to print to "display: none;" 3) No need for a button as by default, clicking the browser's print button will only print portions that you didn't specify in your print style sheet. If you insist on using a print button, though I see no reason y, assuming my approach above, you just do on the button: onclick="window.print()". make sense? good luck! |
Re: How To Code The Printing Of A Particular/desire Space On A Web Page by ogzille(m): 7:58pm On Nov 18, 2009 |
You can use the stylesheet solution as the previous guy mentioned, but if u must have a button then use this: Add an iframe to the page, set the size to the minimum possible size or set display to none. On the onclick event of the print button add this function function printDiv(pd, frame) { var copyto = document.getElementById(frame); var content = document.getElementById(pd).innerHTML; var doc = (copyto.contentWindow || copyto.contentDocument); if (doc.document) { doc = doc.document; } doc.write("<head><title>your page title</title></head><body onload='this.focus(); this.print();'>" + content + "</body>" doc.close(); } argument 1: pd is the id of the element u want to print its content and frame is the id of the iframe. You can change he values to suit. Hope it helps. |
Re: How To Code The Printing Of A Particular/desire Space On A Web Page by yawatide(f): 8:10pm On Nov 18, 2009 |
yep, the above might work but IMHO, using the stylesheet approach requires less code (hence is easier to maintain), and degrades gracefully |
(1) (Reply)
Working With Facebook As A Query Language / Power Is The Real Reason Why You Should Learn To Program / Programmers In Ilorin!!!! Help A Newbie
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18 |