Jacascript: targeting frame for printing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gpig
Forum Newbie
Posts: 15
Joined: Sat Apr 17, 2004 2:52 am

Jacascript: targeting frame for printing

Post 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
gpig
Forum Newbie
Posts: 15
Joined: Sat Apr 17, 2004 2:52 am

Post by gpig »

Sorry, posted this in wrong section, had 2 pages open, oops
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

you might need to rename it - is main a reserved word?
gpig
Forum Newbie
Posts: 15
Joined: Sat Apr 17, 2004 2:52 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try:
document.frames.main.window.print();
Guilherme Blanco
Forum Newbie
Posts: 12
Joined: Wed Jun 02, 2004 4:58 pm
Location: São Carlos - SP/Brazil
Contact:

Post 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,
gpig
Forum Newbie
Posts: 15
Joined: Sat Apr 17, 2004 2:52 am

Post 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.
Post Reply