codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || RAM 
Search Site:



DHTML/Javascript Specifying page breaks for printing

Article by:  Jeff Anderson  ( 1362 ) (3/15/2002)
Bookmark us now! Add to Favourites
Email a friend! Tell a friend
Summary: Configure your page so that it still looks good when you print it out, by using javascript/dhtml page break functionality.
Viewed: 38645 times Rating (12 votes): 
 5 out of 5
  Rate this Article   Read Comments   Post Comments



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>






Useful Links


CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on ' DHTML/Javascript Specifying page breaks for printing '








Recent Forum Threads
•  Run a program both on windows and linux
•  VERO.SurfCAM.v2014
•  Schlumberger.Petrel.V2013.2
•  Petrel.V2013.2
•  Altair.HyperWorks.v12
•  VoluMill.v6.1
•  VoluMill.NEXION.6
•  VERO.SurfCAM.v2014
•  Schlumberger.Petrel.V2013.2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2015