| Author |
Message |
KAN Experienced Member

 Joined: 28 Jul 2005 Posts: 72 Location: Indonesia
|
Posted: Tue Dec 02, 2008 4:19 am
Post subject: Controlling browser's print options with JavaScript? |
|
|
Although each browser's print options is different (for example, "Print Options" in Opera, and "Page Setup" in Internet Explorer), it seems they handle similar set of parameters, like:
- header and footer
- print margins
- paper size and orientation
Could I control those browser's parameters with JavaScript? Or better, with CSS? Internet Explorer is particularly annoying by enabling header and footer by default. Could I, for instance, write a JavaScript to disable browser's header and footer?
I'm also writing a web-based application that are supposed to print pages in exact size (A4, etc). I try to achieve the HTML page size by the following:
| Code: | <html>
<head>
</head>
<body>
<table border=1 style="width:29.7cm;height:21cm";border-color:black">
<tr><td>A4</td></tr>
</table>
</body>
</html>
|
The code above give me exact A4 page size on screen, especially since I disable HTML page margin (<body>). Alas, when printing, the browser's margins still exist, ruining the print result. Is it possible to set browser's margins to zero (all of them; Top, Bottom, Left, Righ) using JavaScript? |
|
| Back to top |
|
 |
wardrich lawl catz r lawlz

 Joined: 14 Sep 2002 Posts: 3361 Location: Ontario Canada
|
Posted: Tue Dec 02, 2008 5:15 am
Post subject: |
|
|
I could see how something like this could be taken for evil... especially if there's a way to bypass all user interaction.  |
|
| Back to top |
|
 |
fauvem Expert

 Joined: 14 Aug 2006 Posts: 152 Location: A non-specific pacific island
|
Posted: Tue Dec 02, 2008 6:39 am
Post subject: |
|
|
| I'm quilty of such evilness but in a different scripting language. I'll see if the code is still floating around. |
|
| Back to top |
|
 |
AdamN Lord of Gaming

 Joined: 29 Oct 2006 Posts: 265 Location: in your basement with a blood-covered axe
|
Posted: Sun Dec 14, 2008 4:06 am
Post subject: |
|
|
To my knowledge, Javascript can't read hardware or peripheral devices to print a page with a specific paper size, nor can it remove the header or footer of the page you are printing, the easiest option would be to put a download of a printable document on your site, where users can download the document and print it without the headers and footers.
However, try this in CSS:
| Code: |
body { background-colour:#EFEFEF;
margin:0px auto !important;
padding:0px auto !important;}
#A4 {background-color:#FFFFFF;
left:200px;
right:190px;
height:297mm !important;
width:210mm !important;
margin:1px solid #FFFFFF; }
|
and add it in HTML with this:
in body type
| Code: | <div id="A4"></div>
|
save and test. |
|
| Back to top |
|
 |
KAN Experienced Member

 Joined: 28 Jul 2005 Posts: 72 Location: Indonesia
|
Posted: Sun Dec 14, 2008 5:09 am
Post subject: |
|
|
| Thanks! I'll definitely try. |
|
| Back to top |
|
 |
|