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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing frames

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
Hiya,

Can anyone help me with a problem I'm having printing a page which contains a frameset, which in turn contains a number of frames. I want to print the frames "As Laid Out On Page", as it were, but I can only seem to print either the active frame or all the frames separately.

Here's the pertinent bits of script I'm using to get as far as I've got;

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf(&quot;Mac&quot;) != -1);

function printPage(frame, arg) {
if (frame == window) {
printThis();
} else {
link = arg; // a global variable
printFrame(frame);
}
return false;
}

function printThis() {
if (pr) { // NS4, IE5
window.print();
} else if (da && !mac) { // IE4 (Windows)
vbPrintPage();
} else { // other browsers
alert(&quot;Sorry, your browser doesn't support this feature.&quot;);
}
}

function printFrame(frame) {
if (pr && da) { // IE5
frame.focus();
window.print();
link.focus();
} else if (pr) { // NS4
frame.print();
} else if (da && !mac) { // IE4 (Windows)
frame.focus();
setTimeout(&quot;vbPrintPage(); link.focus();&quot;, 100);
} else { // other browsers
alert(&quot;Sorry, your browser doesn't support this feature.&quot;);
}
}

if (da && !pr && !mac) with (document) {
writeln('<OBJECT ID=&quot;WB&quot; WIDTH=&quot;0&quot; HEIGHT=&quot;0&quot; CLASSID=&quot;clsid:8856F961-340A-11D0-A96B-00C04FD705A2&quot;></OBJECT>');
writeln('<' + 'SCRIPT LANGUAGE=&quot;VBScript&quot;>');
writeln('Sub window_onunload');
writeln(' On Error Resume Next');
writeln(' Set WB = nothing');
writeln('End Sub');
writeln('Sub vbPrintPage');
writeln(' OLECMDID_PRINT = 6');
writeln(' OLECMDEXECOPT_DONTPROMPTUSER = 2');
writeln(' OLECMDEXECOPT_PROMPTUSER = 1');
writeln(' On Error Resume Next');
writeln(' WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
writeln('End Sub');
writeln('<' + '/SCRIPT>');
}

function closeTheWindow() {
document.close();
window.close();
parent.close();
}
// -->
</SCRIPT>



Then an image with the following attached to it;

OnClick=&quot;printPage(parent, this)&quot;


This'll print all the frames on the page individually - is there any way to make the frames print as they're laid out on the screen?



Any help will be much appreciated,

Thanks,

Paul
 
woo.. so much code..
here is something from faqs:

function printit()
{
top.window.focus();
top.window.print();
}
& it is said that it would print the hole frameset.. (didn't tryed, but may be it would help you somehow..) Victor
 
Hiya,

OK, for anyone who was hoping somebody would come up with a cool solution to this one - here's the best I came up with;

I modified the frameset to contain an aditional frame of zero size, so that it was hidden. Then, I placed the <Body> contents of my other frames between <Span ID=...> tags, giving each section a different ID. The additional frame was set to contain <Span ID=...></Span> tags, where the ID's were those of the frames I'd previously placed within <Span ID=...> tags. With me? Cool. So, then, when I wanted to print, I used all the same code as in my previous posting, but in the OnClick event, I copied the contents of each Span section into the hidden frame, a bit like this;

OnClick=&quot;parent.hiddenframe.span1.innerHTML=parent.frame1.span1.innerHTML; parent.hiddenframe.span2.innerHTML=parent.frame2.span2.innerHTML; return printpage(parent.hiddenframe,this)&quot;

This way, the content of all other frames can be printed as though they were a single frame - the benefit of this is that the seperate frames don't end up printing on seperate pages and the entire content of those frames can be passed onto the printer (not just the content that can be seen on the page).

An additional benefit of doing it this way is that, in my case, the content of each frame is a representation of a recordset retrieved from an SQL database and this avoids performing additional queries to populate the hidden frame (or, as I've seen it done elsewhere, a &quot;printer friendly&quot; page).

Thanks to everyone who had a think about this for me :)


Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top