...

View Full Version : Print/preview shows only 1 first print page for the iframe



SlavaTT
07-14-2004, 11:48 AM
Hi,

Let me describe problem.
I have multiple iframes on the page.htm and and I want to print them all with
window.print() call on page.htm. I resize iframes to the size of document they contain.
Now when I open Print Preview in IE 6 (loaded with page.htm) it shows me only 1 first print_page for each iframe, even if document in the iframe has more that 1 print_page.
Say I have 2 iframes on the page.htm and each iframe has a document that produces 2 print_pages (if that document opened separately) and number of pages shown in the Print Preview should be 4 but I see only 2, eq. 1 first print_page for each document.

Is it possible to make IE 6 (and in NS 6 if possible) to preview and then print All print_pages for each of iframes my page.htm contain ?
Are there any APIs except of (window.print() and 2 CSS styles) to have more control on printing ?

Thanks

Slava

glenngv
07-14-2004, 12:18 PM
Is there any compelling reason you're using iframes?

Normally, you can only print one window, frame or iframe at a time. One possible workaround is to have an invisible iframe and put the contents of the desired iframes there.


function printIFrames(){
var html='<html><body>';
for (var i=0;i<window.frames.length;i++){
if (window.frames[i].name!="printFrame") html += window.frames[i].document.body.innerHTML;
}
html += '</body></html>';
var printFrame = window.frames["printFrame"];
printFrame.document.write(html);
printFrame.document.close();
printFrame.focus();
printFrame.print();
}
...
<iframe src="page1.htm"></iframe>
<iframe src="page2.htm"></iframe>
...
<iframe name="printFrame" src="about:blank" style="display:none"></iframe>
<input type="button" value="Print" onclick="printIFrames()" />

SlavaTT
07-14-2004, 12:46 PM
Hi Glenngv,

Thanks for your reply.
Reason is I need to print multiple different pages from different web sites as a one print job.
So I decided to try to put them in separate iframes of one page.htm and call window.print() on it.
I can call window.print() on each iframe in onload event but user would see may popup print dialogs and click print many times.
I could put all page's content into a one iframe or just on the page.htm
but those pages are different documents and can contain any scripts etc.
so I don't think it would work at all.

Slava

glenngv
07-14-2004, 12:59 PM
You have no chance of making it worked if the pages are in a different domains. For security reasons, you have no access to the frames/iframes that points to external pages.

SlavaTT
07-14-2004, 01:17 PM
Yes, I've found out that (a couple of days before) that
window.document.frames[i].document produces access denied error.

But I want to add that I have all those pages texts (I want to print together)in my mssql table (in the ntext field). So I am free to add anything into those pages on fly. I added a call to my function SetFullSize() to resize iframe (in hope it could be printed) into each page's onload handler, so if SetFullSize() is called from iframe's document it can access window.document.frames[i].document.
My multi-iframed page.htm is actually page.aspx.

Slava

SlavaTT
07-14-2004, 01:24 PM
Thinking maybe I should not use those iframes but write some little COM object with ATL and print everything from it ?
Just those COM object security problems stop me.

glenngv
07-15-2004, 04:34 AM
But I want to add that I have all those pages texts (I want to print together)in my mssql table (in the ntext field). So I am free to add anything into those pages on fly. I added a call to my function SetFullSize() to resize iframe (in hope it could be printed) into each page's onload handler, so if SetFullSize() is called from iframe's document it can access window.document.frames[i].document.
My multi-iframed page.htm is actually page.aspx.

Slava
If you have all their data in your db, then make a single page that accesses your db and print that single page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum