...

View Full Version : page breaks



robert orlini
06-04-2004, 04:53 PM
What JavaScript can I use for page breaks?

Is there a good JavaScript for clicking a button and sending a page to print?

Thanks.

RO

bherrington
06-04-2004, 05:54 PM
Not sure about page breaks, but yes you can print using javascript, I found something in the past at www.cgiscript.net, although as I couldn't find it again there when I looked to day to give you the link, I've reproduced it here.


This Script allows users to print the current html page.

//1. INSERT THE FOLLOWING IN THE HEAD SECTION

<script language="Javascript1.2">
<!--
// ***********************************************
// AUTHOR: WWW.CGISCRIPT.NET, LLC
// URL: http://www.cgiscript.net
// Use the script, just leave this message intact.
// Download your FREE CGI/Perl Scripts today!
// ( http://www.cgiscript.net/scripts.htm )
// ***********************************************

function printWindow(){
browserVersion = parseInt(navigator.appVersion)
if (browserVersion >= 4) window.print()
}

// -->
</script>


//2. INSERT THIS IS THE BODY SECTION

<a href="javascript: printWindow()">Print This Page</a>

sidvorak
06-04-2004, 06:46 PM
page breaks can be controlled by CSS properties. However, you need an element to attatch them to. So maybe you have...



<p id="p1">...stuff...</p>
<p id="p2">...more stuff...</p>

You could use javascript to apply one of the page-break rules to say the paragraph with id="p2". There are a few different rules for a page break. page-break-before, page-break-after, and page-break-inside. I tend to use page-break-after.

To attatch it in javascript try something like...


<script type="text/javascript" language="javascript">
<!--
function breakin(){ //shameless 80's dance movie reference
if(document.getElementById){ //check for DOM. might need to make it more complicated for *****y browsers

p=document.getElementById("p1");

//The CSS rule is page-break-after, but in Javascript you have to reference it as pageBreakAfter
p.style.pageBreakAfter="always";

}
}
window.onload=breakin; //attatch it after the page loads.
//-->


Hope that helps!:thumbsup:

Cheers,
Simon (http://www.simondvorak.com)

glenngv
06-07-2004, 06:58 AM
You can even do it without javascript.

<style type="text/css">
.newPage {page-break-before:always;}
</style>
...
<h2>Header 1</h2>
<p>
This is Paragraph 1 in Header 1.
</p>
<p>
This is Paragraph 2 in Header 1.
</p>

<h2 class="newPage">Header 2</h2>
<p>
This is Paragraph 1 in Header 2.
</p>
<p>
This is Paragraph 2 in Header 2.
</p>

Or if you want all h2 tags to be in new pages, you can simplify the CSS like this:
<style type="text/css">
.h2 {page-break-before:always;}
</style>

Garadon
06-07-2004, 02:12 PM
<style>
.pagebreak{page-break-before:always;}
</style>
<br class="pagebreak">

glenngv
06-08-2004, 03:04 AM
What's the difference of that with my suggestion except of course of the tag used?

Garadon
06-08-2004, 05:31 AM
there is no exception at all, I just forgot to write that I thought a break tag would be more appropriate to use doing a break.

glenngv
06-08-2004, 05:54 AM
IMO, you usually want a page break in between topics (usually preceded by <hn> tags) or paragraphs (<p>) or divisions (<div>) but probably rarely in newlines (<br>).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum