View Full Version : page print with limiters java script

01-03-2004, 03:54 PM
Would need a print a page java script type:

if (window.print) {
document.write('<form><input type=button name=print value="Imprimir factura" onClick="javascript:window.print()"></form>');

but that would only print a partial part of the page.

Any ideas ?

01-03-2004, 05:59 PM
What do you mean? window.print() will print the entire page (or entire frameset, if selected). Why do you think it would only print part of the page?

01-03-2004, 06:10 PM
Sorry Skyzyx, maybe I was not clear.

I need a java script to print only part of the page that i can choose.

01-03-2004, 06:32 PM
Well, you can do that... but... it may be more work than you're up for today.

Pages designed according to web standards are very, very good at accomplishing this sort of thing. Using correct, validated (http://validator.w3.org), semantic code for markup, and using only CSS for text styling and layout (NOT Tables) makes sites not only easier to maintain, but also lowers bandwidth costs, improves accessibility without hardly even trying, and makes printer-friendly pages a snap! Learning these methods is the only way that anyone can ever really progress in web design.

Now, with that being said (and since I haven't seen the entirety of your code), you could use stylesheets to accomplish this... no JavaScript is required.

In your web page, I'll have to assume that you are aware what stylesheets are (CSS) and how to use them. If not, then this situation is way unworkable.

Here's a sample of what you should have:

<link href="default.css" rel="stylesheet" media="screen" />
<link href="printer.css" rel="stylesheet" media="print" />

The first line is your normal stylesheet, except that you specify that it is used only for the screen. The second is your stylesheet for determining how the printed page will look. Inside that page, you'll want to figure out what part you want to print out. Once you find that section, there will be code before it and after it. In the code before it, wrap it all in a div tag and add a "printhide" class. Do the same for the code after it. In your printer stylesheet, add the following:

div.printhide { display:none; }

It may be a bit of work to get it all to work how you want it to (as I said earlier, designing using web standards makes this a breeze), but if you do it right, this will work.

Hope this helps! :thumbsup: