Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript print function

Status
Not open for further replies.

skibascott

IS-IT--Management
Mar 18, 2004
82
US
I have an intranet page that contains between 1 to 4 iframes one of them containing a pdf and the rest of the iframes containing html. These iframes are populated with the documents based on the user's selection. It is important that if the user chooses to print these iframes, that all of the documents are printed. I cannot expect our user's to click the print button and use the print dialog box for each single document.

Now, correct me if I am wrong, but I understand there really is no way to print all of the iframes with one javascript print button. I can use the print function to open a windows print dialog box for each of the iframes(therefore having to choose a printer and click OK four times), but cannot click the button to open the print dialog box and choose my printer and click ok and have all of the iframes print.

If there is no way around this, then would it be possible to load all of the documents into a single iframe and print that single iframe with the javascript print function? Is there any other ways to accomplish this?
 
the iframes are situated in a page right? give a print button for that page????

Known is handfull, Unknown is worldfull
 
I have tried that, but then the html page prints. I only want to print the documents in the iframes.
 
then the best way is to give a printable version where u open a popup with just those iframes and print the popup. u can also look at css as an option (print media option)...

Known is handfull, Unknown is worldfull
 
With the way I have this setup I would really like to have the users viewing the documents in the iframes fixed on the main page.
So, if I did open a new popup window to display the print version, would it be possible to start the print dialog automatically when the new window opens, and then close the window after a few seconds or less?
And, if this is possible can I put multiple documents from different sources into a single printable iframe?
 
>>when the new window opens, and then close the window after a few seconds or less

yes,

<body.... onload="window.print();setTimeOut("window.close()",5000)">

that will automatically start pritning the page and close it after 5 seconds.

i dont get ur second part...

Known is handfull, Unknown is worldfull
 
thank you for your help vbkris.

the only thing i am trying to accomplish is printing multiple documents with one single action.
so far i have accomplished to load each of these documents(ie. abc.pdf, defg.doc, and hijkl.htm) into their own iframe that is embedded on an html page containing other content as well. the number of documents and which documents to display is dependent on what option the user chooses.
this is great for viewing the documents, but as far printing, the user has to print each individual document. to ask the end user to do this is ridiculous because there can be up to five or six documents. i would like a button on this page that will print all of these documents at once. if this in not possible then any suggestions are welcome.

 
How about this?
Code:
// Enter your own pages
var pages = new Array("page1.html","page2.html","page3.html");

function printAll(index, prev_win)
{
  if (prev_win) prev_win.close();
  if (index >= pages.length) return;
  var page = pages[index];
  var win1 = window.open(page,"printwin");
  win1.print();
  setTimeout("printAll(" + index + "," + win1 + ")",5000);
}

This is untested but should work. Call it like this:
Code:
<a href="#" onclick="printAll(0,null);return false;">Print them all!</a>


--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 

When I try this the first page opens, as well as the print dialog box. But there is a javascript error on the original page:

'object' is undefined
line 1 column 1

Even if I did get past the error, won't I still have to choose my printer and click OK for each document to be printed?

 
Another version (should work):

Code:
// Enter your own pages
var pages = new Array("page1.html","page2.html","page3.html");

var prev_win = null;

function printAll(index)
{
  if (prev_win) prev_win.close();
  if (index >= pages.length) return;
  var page = pages[index];
  var prev_win = window.open(page,"printwin");
  prev_win.print();
  setTimeout("printAll(" + index + ")",5000);
}

Call with:
Code:
<a href="#" onclick="printAll([red]0[/red]);return false;">Print 'em all!</a>

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
I tried that. No error, but I did get about 20 print dialog boxes to pop up one after the other.

The goal is one print dialog box that will print all documents.
 
no way to avoid that without activex controls, which is the same as saying, "you have 24 hours to live, unless you take this poison." (to me)

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
actually, even with activex controls, you'll still get a prompt for ok/cancel

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
How about creating only one page and appending all the other pages to it? It would require finding how high the printed page is and putting the pages in <div>s that are that height... Seems complicated to me.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
At this point, I will try anything to get this to work. Could you explain the <div> idea a bit more?
 
Actually, this should be done through server-side scripting. With whatever scripting language you choose, read a list of files from the heading (GET method, comma-delimited), load those files, and output them sequentially, eliminating repetition (<html> tags, <body> tags, etc). Place each of these in a div that is a printer page high (not sure how to retrieve the length of the printer page in pixels, but that should be minor).

Function for calling the page:
Code:
// Add your own pages
var pages = new Array("page1.html","page2.html","page3.html");

function printAll()
{
  var url = "allPages.php";
  if (pages.length > 0)
  {
    url += "?pages=" + pages[0];
    for (var i=1; i<pages.length; i++)
    {
      url += "," + pages[i];
    }
  }
  var printpage = window.open(url,"printpage");
  printpage.onload = printpage.print;
  }
}

This is untested. See the chosen server-side language for details.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top