PDA

View Full Version : Using an input button to print


ScottInTexas
12-09-2002, 07:52 PM
I have put a button in an IFrame in my document. The onClick method calls the doPrint function.


function SetPrintButton(){
var objFrame=self.frames['printFrame'];
var printButton='<input type="button" value="Print Table" onClick="parent.doPrint()">';
with (objFrame){
document.write(printButton);
}


}

function doPrint(){
alert("I am in do print " );
print(self.frames['dataWindow'].text);

}

or


function doPrint(){
alert("I am in do print " );
print(parent.frames['dataWindow'].document);

}



If I leave out the 'self' or 'parent' nothing hapens at all. Isn't the parent also the self in this case?

The button is written correctly and calls the doPrint function but prints the contents of itself, in other words a nice button is printed on the paper. The name of the frame which is occupied by a large table is dataWindow.

I have tried passing the dataWindow.document to the print function and I have tried accessing the document using the parent.frames['dataWindow'].document. I had read somewhere that text was a member of the document object, but now I can't find that reference.

This print does call up the print dialog, so I just need it to point to the right document.

Any ideas?

chrismiceli
12-09-2002, 11:35 PM
http://www.faqts.com/knowledge_base/view.phtml/aid/3210/fid/128
did a quick google search.

Quiet Storm
12-10-2002, 12:20 AM
And this is what I use to print only the iFRAME named 'thisi':

<A HREF="javascript:window.frames['thisi'].focus();window.frames['thisi'].print();">print</A>

I have to set focus() to the iFRAME before I can print it...

:D

ScottInTexas
12-10-2002, 11:04 PM
Thanks for your replies.

Neither of these options worked. It may be that the button is located in an iframe in a table cell which is different than the table that I want to print.

I think my overall problem is the proper addressing of the individual elements on the page.

All input is appreciated.

glenngv
12-11-2002, 01:42 AM
try this:

function doPrint(){
alert("I am in do print " );
top.frames['dataWindow'].focus();
top.frames['dataWindow'].print();
}

ScottInTexas
12-12-2002, 05:24 PM
Thanks for the reply,

Sorry, it didn't work.

Any other idea?

glenngv
12-13-2002, 01:07 AM
maybe you could post the whole code or link to your site