Click to See Complete Forum and Search --> : Page print without headers and footers
hampstead
12-16-2002, 01:32 PM
I have an application where users build and print forms from their browsers (fax cover sheets, proposals, etc.). Is there a way to inhibit the header and footer in the print using javascript.
Can browser "Page Setup" features like header and footer formats, or the inhibiting of header and footer printing be done in javascript?
I would also be nice to be able to "Print Background" on a page by page basis. Can this be done using javascript?
Thanks for any help you can provide!
Matt
khalidali63
12-16-2002, 02:51 PM
Nope,
looks like you are out of luck there,
there is a word that JavaScript 2 will have more flexibility when it comes to access resources on a given machine...
sorry..
Oh yea...unless you use xsl-fo
:-)
Khalid
jeffmott
12-16-2002, 03:48 PM
Personally I don't think JavaScript should have more access on a given machine. I'd like to think that the settings _I_ choose to have on _my_ computer will remain that way. Besides, who are you (any Web developer) to decide for me what I do or do not want with my printouts?
Already many people surf the Web with JavaScript off due to the annoyances it brings. If a newer JavaScript were to give the developer more control over the client machine, I can almost guarentee you that the number of people with JavaScript disabled will increase dramatically.
Already much of the fuctionality of JavaScript is redundant and is used as such. A print link instead of a browser's own print button that is no more than a click away, or an add to favorites link as if doing this was not already easily handled by the browser itself. And any form validation should really all be done server-side
The thread disable back option in web browser (http://forums.webdeveloper.com/showthread.php?s=&threadid=884) describes another reason why I would personally disable JavaScript.
...but of course this is all just my opinion.
IanSane
12-16-2002, 04:05 PM
I found a way to remove parts of a page from printing using divs and the onbeforeprint and onafterprint event handlers. I used it to prevent a print button from being printed
First of all anything that you don't want to printed has to be within a div tag with an id.
<div id="myheader">
Stuff I don't want to be printed.
</div>
You then use the onbeforeprint event handler to make the div invisible and the onafterprint handler to bring it back.
<body onbeforeprint="myheader.style.display='none';" onafterprint="myheader.style.display='block';">
This should make it so everything within the div myheader won't appear on the print out. In theory you could make a function to do this with many divs and therefore have several parts of a page "disappear" on print out though I've never tried it with multiple divs.
I've tested this in Explorer and Netscape.
hampstead
12-16-2002, 04:59 PM
Thanks everyone for the response.
I understand jeffmott's point about limiting access to browser settings, it makes a great deal of sense.
The problem I face is my app's intended target audience are individuals with very little computer experience and no clue how to change browser settings. If the print-outs contains things they do not like (like headers and footers) they'll go back to the manual process. I was hoping to make this app a no-brainer.
Thanks again!
Matt
Charles
12-16-2002, 05:13 PM
If you want to do the job properly, then use FOP server side to create a PDF version of the form on the fly. No unwanted headers or footers and you can embed fonts. See http://xml.apache.org/fop/index.html.