Controlling browser's print options with JavaScript?

Anything else unrelated to gaming can go here.
Post Reply
User avatar
KAN
Experienced Member
Experienced Member
Posts: 72
Joined: Thu Jul 28, 2005 3:13 pm
Location: Indonesia

Controlling browser's print options with JavaScript?

Post by KAN »

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: Select all

<html>
<head>
</head>
<body>
<table border=1 style="width&#58;29.7cm;height&#58;21cm";border-color&#58;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?
ImageImage
User avatar
wardrich
"Some Troll"
Posts: 3944
Joined: Sat Sep 14, 2002 9:08 pm
Location: Ontario Canada

Post by wardrich »

I could see how something like this could be taken for evil... especially if there's a way to bypass all user interaction. :devil:
User avatar
fauvem
Expert
Expert
Posts: 155
Joined: Mon Aug 14, 2006 6:36 pm
Location: North of Embarrassment, South of Dignity

Post by fauvem »

I'm quilty of such evilness but in a different scripting language. I'll see if the code is still floating around.
"I had One thing to do, don't play nostalgic games and look what happened... Here I am"
User avatar
AdamN
Lord of Gaming
Lord of Gaming
Posts: 261
Joined: Sun Oct 29, 2006 2:19 am
Location: in your basement with a blood-covered axe

Post by AdamN »

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: Select all

body &#123; background-colour&#58;#EFEFEF;
           margin&#58;0px auto !important;
           padding&#58;0px auto !important;&#125;
#A4 &#123;background-color&#58;#FFFFFF;
        left&#58;200px;
        right&#58;190px;
        height&#58;297mm !important;
        width&#58;210mm !important;
        margin&#58;1px solid #FFFFFF; &#125;
and add it in HTML with this:

in body type

Code: Select all

 <div id="A4"></div>
save and test.
<img src="http://iphonehellas.files.wordpress.com ... d-kill.jpg" border="1" bordercolor="#363636" width="298" height="148" alt="">

<font face="Arial" color="660000">
Nobody's More Disturbing!!
</font>
User avatar
KAN
Experienced Member
Experienced Member
Posts: 72
Joined: Thu Jul 28, 2005 3:13 pm
Location: Indonesia

Post by KAN »

Thanks! I'll definitely try.
ImageImage
Post Reply