views:

27

answers:

2

I have a print function using JavaScript that prints just the contents of the iFrame and not the page the iFrame is in. What I want to do is have a DIV or something in the page being access through the iFrame that will go visible when you print and have a legend on it and then it will go back to invisible once the page is printed? Any help on how to do this? I am not the most adept at using JavaScript but will try it.

Thanks,

A: 

The IFrame Javascript element has a document property, which works identically to the normal page's document property.

That being said, if your IFrame's framed page is on a different domain from your framing page, you are probably out of luck. Browsers limit what one site can do to another site to prevent cross-site scripting attacks, and these limits will prevent you from accessing the framed page's document (unless it's on the same domain or you setup a cross-site file on the framed page's server).

machineghost
It is on the same domain.
c8irish
A: 

Forget the JavaScript. Trying to fiddle the page around a print from script is complicated, fragile and pointless. This is what a print stylesheet is for!

Add a stylesheet with media="print" which contains display: rules to hide all the parts of the part you don't want printed, and cause normally-hidden parts of the page to appear when being viewed on a printer. You don't even need a scripted print button, the normal web browser Print function will pick up the differences.

bobince