Hi to everybody
I've a little problem that I can't solve. An hour of Google search
didn't help.
I should set dinamically via JavaScript the height of an object when I
print the HTML page.
I already know that it would be possible with the stylesheets,
specifying media="print" as in the following example:
<STYLE type="text/css" media="print">
DIV#Thing
{
height:3cm;
}
</STYLE>
....
<DIV id="Thing">Hello!</DIV>
But I'm not able to set the height with JavaScript only for prints: if I
use a script like this
<SCRIPT type="text/javascript" language="javascript">
function SetHeight(h)
{
var p;
p=document.getElementById("Thing");
p.style.height=h+"cm";
}
</SCRIPT>
The code resizes "Thing" at screen too, but I'd like to do that only for
prints.
I could use a CSS with every height:
<STYLE type="text/css" media="print">
..Height1
{
height:1cm;
}
..Height2
{
height:2cm;
}
..Height3
{
height:3cm;
}
/* Etc... */
</STYLE>
along with a function like this:
<SCRIPT type="text/javascript" language="javascript">
function SetHeight(h)
{
var p;
p=document.getElementById("Thing");
p.className="Height"+h;
}
</SCRIPT>
But:
1) it is quite long to do and not very clever
2) I should write a huge number of classes, since the height could range
from 0.1cm to 100cm
I tried also with the events onbeforeprint and onafterprint: I set the
height of Thing when onbeforeprint raises, and I reset it when
onafterprint is called. This works great with Internet Explorer (tried
with IE6), but with Firefox 1.0 and Opera v7.23 the two events aren't
being called.
Does anybody could help me?
Thank you
Michele