Solved

Printing multpile pages with javascript

Posted on 2004-08-03
2
1,674 Views
Last Modified: 2012-06-27
Is there an easy way of printing a range of html pages from a javascript on the first page ?
Ideally this should not involve loading those pages visibly into the browser, but this might be too much to ask.
0
Comment
Question by:niner
2 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 125 total points
ID: 11706828
The best way I can think of is to popup windows. The windows themselves, in their <body> should have onload="opener.focus();" to lose focus. (or self.blur(); if you want)

The first page you want to print would have this:
<body onload="opener.focus();window.print();self.close();" onunload="window.open('nextPrintPage.html','printPage','');">

Each following printed page would have the same thing. The last printed page will just not have the onunload at all.

Of course, each of this displays the print dialog. If you want it gone (and I'm warning you that if you don't tell the users clearly there will be no dialog, you'll get tons of negative feedback):

http://www.experts-exchange.com/Web/Q_21068168.html

my accepted answer
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11708355
You can load the pages into hidden layers and then using styling to make them visible to the printer as needed:

<html>
<head>
<title> multi page print </title>
<style type="text/css">
@media print {
.printyes {display:block}
.printno {display:none}
}
</style>
<script type="text/javascript">
var pagecnt=6;
var str='page0';
var i=0;
function printMulti()
{
   window.print();
   document.getElementById(str).className='printno';
   i++;
   str='page'+i;
   document.getElementById(str).className='printyes';
   if (i<pagecnt)
   setTimeout('printMulti()',2000);
}
</script>
</head>
<body>
<div id="page0" class="printyes">
Main page of content here and visible on the screen
</div>
<div id="page1" class="printno" style="display="none">
page 1 content not displayed on the screen
</div>
<div id="page2" class="printno" style="display="none">
page 2 content not displayed on the screen
</div>
<div id="page3" class="printno" style="display="none">
page 3 content not displayed on the screen
</div>
<div id="page4" class="printno" style="display="none">
page 4 content not displayed on the screen
</div>
<div id="page5" class="printno" style="display="none">
page 4 content not displayed on the screen
</div>
</body>
</html>


The timeout between pages is to give enough time for the page to transfer before chaning the setup for the next page. The only page that needs any cod on it is the first page.  If the pages are actually seperate files you will probably need to use XMLHTTP to load the layers in background, or perhaps a hidden frame/iframe.

I would not advise doing this unless the users are aware that they are going to get additional pages when they print; as you could make a lot of people angry and get your site on lists of bad sites that should not be re-visited.

Cd&
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now