@page and style

A

Andrew Poulos

To set an item's style properties I can do something like this:

var foo = document.getElementById("bar");
bar.style.width = "100px";

But how do I set the style of paged media i.e. the @page rule?

Specifically I need to set this CSS:

@page {
size: landscape;
margin: 10%;
}

Andrew Poulos
 
T

Thomas 'PointedEars' Lahn

Andrew said:
[...] how do I set the style of paged media i.e. the @page rule?

Specifically I need to set this CSS:

@page {
size: landscape;
margin: 10%;
}

var s = document.createElement("style");
if (s)
{
s.type = "text/css";

s.appendChild(
document.createTextNode(
"@page { size: landscape; margin: 10%; }"));

document.getElementsByTagName("head")[0].appendChild(s);
}


HTH

PointedEars
 
A

Andrew Poulos

Thomas said:
Andrew said:
[...] how do I set the style of paged media i.e. the @page rule?

Specifically I need to set this CSS:

@page {
size: landscape;
margin: 10%;
}

var s = document.createElement("style");
if (s)
{
s.type = "text/css";

s.appendChild(
document.createTextNode(
"@page { size: landscape; margin: 10%; }"));

document.getElementsByTagName("head")[0].appendChild(s);
}
Sadly:

IE 7 complains that
Error: Unexpected call to method or property access.
At the "s.appendChilde" line.

FF 3 gives the error:
Unrecognised at-rule or error parsing at-rule '@page'.

Opera 9.5 is happy (no error and the page prints in landscape).

Safari ignores it (no error but the page prints in portrait).

Chrome ignores it (no error but the page prints in portrait).

Looking it a bit more it seems that the @page rule may not be supported.
It was dropped from CSS 2.1 :-(

Andrew Poulos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top