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

printing frame(s) contained within an iframe

Status
Not open for further replies.

jaredsark

Programmer
Oct 19, 2005
5
US
i've monkeyed around with this task for hours, trying to figure out a way to access a frame within an iframe for printing. i'm beginning to believe it's not possible.

printing iframe contents is no problem -- unless the contents are another frameset, then i get a blank page. i thought i could hook into a specific frame name to print it (i don't need the entire frameset printed), but either that's not possible, or i'm not utilizing the dom correctly.

i have no control over the source code, and no element IDs are provided -- only names, which i do know in advance.

so is it possible to get at a frame contained within an iframe to print it?

thanks!
 
yes.

try something like:

Code:
window.frames['iframeName'].frames['subFrameName'].print();

or possibly:

Code:
document.getElementById('iFrameID').frames['subFrameName'].print();

keep in mind though, that if the subframe contains a file not in your domain, you might not be able to do this anyway - for security purposes.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
thanks for the quick reply, clflava.

unfortunately, i could not get your suggestion to work. i tried different variations on this theme, but i'm wondering if the difficulty lies with the dom's ability (or inability) to recognize the framed content within the iframe -- and let me get at it.
 
We used to have a problem with the same thing. The solution, we found, was to make sure the frame had focus before you printed it.

Try:
Code:
var d = document.frames[0].document.frames[0];
[b]d.focus();[/b]
d.print();

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
thanks, looking.

your point is correct, however, establishing focus is not my problem. it's getting a hold on the frame itself.

the fact that it resides within an iframe effectively removes it from the document object model of the viewing page (or at least that's what my testing indicates).

i need to get my hands on the frame that is contained within an iframe in my document. i'm not sure it can be done...
 
Thanks, cLFlaVA.

Jared,

This worked for me in IE6. Don't looks solely at my remark about focus(). Consider also the document.frames... line.

Here is how I tested this out.

test.html
Code:
<html>
<body>
<iframe src='test1.html'></iframe>
<input type='button' [red]onclick='var d = document.frames[0].document.frames[0];d.focus();d.print();'[/red] value='print' />
</body>
</html>

test1.html
Code:
<html>
<body>
<iframe src='test2.html'></iframe>
</body>
</html>

test2.html
Code:
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>

test2.html is in the iframe of test1.html which, itself, is in the iframe of test.html. Hitting the print button on test.html prints the body of test2.html.

'hope this helps.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
clflava & dave -- your efforts and time are appreciated.

dave -- your example is great and makes total sense. however, i'm dealing with something a bit different.

using your example, test1 would actually be a document comprised of regular frames, not another iframe.

i have no problem getting at the iframe on the viewing page. i just can't figure out how to get at the individual, regular frames contained within that iframe.

i'm working on a few more possibilities, i feel i'm close, but still not quite there...
 
No problem, jared.

I replaced the code for test1.html with:

Code:
<html>
<frameset rows='100%' cols='100%'>
<frame src='test2.html'></frame>
</frameset>
</html>

...and the results were the same. Without changing the onclick of the parent button, the inner frame printed out fine.

'hope this helps.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
clflava & dave -- again, your responses are very much appreciated.

embarrassingly, i have to admit that due to a semantic error in the frameset structure itself, i could not get your suggestions to work. the frames were not enclosed in correct frameset tags.

so, it will come as no surprise that all of your solutions are apt, and i'm now good-to-go.

thank you both for your patience. although i've been doing this sort of thing for years, i often forget to start with the simplest things first...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top