Page 1 of 1

Jacascript: targeting frame for printing

Posted: Thu Jun 03, 2004 12:16 pm
by gpig
I tried this onClick="main.window.print();return false" to target a Iframe "main", but it prints the whole page and not only the frames content.

Any ideas on how I can target it? Otherwise Ill have to have a print button for each page, but done want that.

Thanx in advance

Posted: Thu Jun 03, 2004 12:17 pm
by gpig
Sorry, posted this in wrong section, had 2 pages open, oops

Posted: Thu Jun 03, 2004 12:22 pm
by magicrobotmonkey
you might need to rename it - is main a reserved word?

Posted: Thu Jun 03, 2004 12:54 pm
by gpig
before I had window.print() to print everything, then someone told me to change it to main.window.print() to target "main"., but didnt work. In Dreamweaver it seems that I can type anything infront of window.print() and it turns blue?
This window.print() method is built into the browser I think, does someone know if there is some parameter configration I can send it? My printer is busted ,so I cant test it often, only every time I get to someone with a printer.

Posted: Thu Jun 03, 2004 1:02 pm
by feyd
try:
document.frames.main.window.print();

Posted: Thu Jun 03, 2004 1:14 pm
by Guilherme Blanco
To be Standards:

If this is a child popup that you want to print the parent:

window.opener.print();

If you are in the parent and want to print the child:

winName.print();

* NOTE: winName = window.open(...);

If you are inside a frame and want to print another one:

top.frames["frameName"].print();

* NOTE: You can use window, but I'm suposing that you have frames, and inside then, you have more nested frames. So, you have to call the top.

If you are calling a JScript function defined in the framed root document (that has the access to all frames in only one level):

document.frames["frameName"].print();



This should help.

Regards,

Posted: Thu Jun 03, 2004 3:50 pm
by gpig
I have an index.html file with an IFRAME called "main" in the page, that IFRAME is inside a table. The print button is in the index.html file, so should I call it like this : main.print(); ? I will rename the frame to something else when I get time to do it all.

Thanx alot for your replies guys,
Ill remember the hierarchy structure for frames like you explained Guilherme, will come in handy in future, thanx.