|
|
DHTML/Javascript Specifying page breaks for printing
|
| Article by: | Jeff Anderson ( 1362 ) (3/15/2002) |
|
| Summary: | Configure your page so that it still looks good when you print it out, by using javascript/dhtml page break functionality. |
|
| Viewed: 29102 times |
Rating (10 votes): |
|
5 out of 5 |
|
|
|
In IE5 and above, and Netscape 6 browsers, you can now specify where page breaks will occur when
the user prints a page.
This is done using Javascript and style sheets. Decide on the tag you wish to use as a page break.
This might be <h2> or <p> or indeed any standard HTML tag.
You then simply set the style for this tag to accept a page break in the following way:
<style>
h1{
page-break-after: always;
}
</style>
| |
|
This will create a page break, immediately after the occurence of any <H1> tag.
The following will do the same, but break before the before:
<style>
h1{
page-break-before: always;
}
</style>
| |
|
You can set the page-break-after and page-break-before attributes to auto if you wish to only
insert a page break if naturally at the end of a page, or you can cancel the operation completely by
setting the tag to ''.
To turn on all H1 elements in a document you can use something like the following:
<script language="javascript">
for (i=0; i<document.getElementsByTagName("H2").length;i++)
document.getElementsByTagName("H1")[i].style.pageBreakBefore="always"
}
</style>
| |
|
|
|
View highlighted Comments
User Comments on ' DHTML/Javascript Specifying page breaks for printing '
|
|
|
Posted by :
Archive Import (kven) at 23:27 on Wednesday, December 18, 2002
|
Thanks a lot Anderson. This helped me on time and isis very useful.
| |
Posted by :
Archive Import (Paul Thibodeaux) at 15:30 on Monday, April 28, 2003
|
This works great for IE.
However, I cannot get this to work for Netscape 6.2.
Has anyone else had this problem?
Am I missing something?
| |
Posted by :
Archive Import (Larry) at 14:16 on Friday, August 22, 2003
|
Thanks so much for the help. I've seen the CSS styles; however, I never realized how to use them.
| |
Posted by :
janapati at 22:26 on Monday, March 29, 2004
|
Hi there,
This is working very well,
i need a help from anyone for my requirement.
im developing a print preview page using xslt, reading content from xml.
to achive my requirement in print preview i need to break the page and insert header on top of every printable page
Now im able to break the page at <H1> but how can i insert a html <table> containing header information using dhtml
anyone can help me pleaseeeeeeeeeeeee
Many thx in advance
| |
|
To post comments you need to become a member. If you are already a member, please log in .
| |