0

I am maintaining a legacy app that is trying to dynamically load some javascript during a postback event. The javascript has a line that tries to print the iFrame that contains the page that is loading the javascript. In other words, the window has a hierarchy of iFrames (a nightmare, I know). My code is in a asp.net page that is loaded within an iFrame with the id 'main'. So, the following code works without any problem from Firefox:

parent.frames['main'].print();

However, I can't seem to find the magical incantation that will get IE to print. I have tried adding this line before the previous line:

parent.frames['main'].focus();

But, that has no effect. Here is a simplified representation of the hierarchy:

<page>
    <frameset>
        <frame id='content'/>
        <frameset>
            <frame id='menu'/>
            <frame id='main'/>
        </frameset>
    </frameset>
</page>

I have seen lots of stuff on the web about this but, haven't been able to get any of them to work across IE, FF.

I am using IE 10 and FF 28

Thanks for any advice you can give. I have wasted far too much time on this.

castis
  • 8,154
  • 4
  • 41
  • 63
rogdawg
  • 687
  • 3
  • 11
  • 33
  • http://stackoverflow.com/questions/9616426/javascript-print-iframe-contents-only – Jonathan Anctil Mar 19 '14 at 18:32
  • I tried parent.window.frames['main'].print(), with no luck (and I tried it the the "focus" statement before it). Since I know the complete hierarchy, I decided to try window.top.frames['main'].print() which, of course, works in FF but not IE, I also tried window.top.frames['main'].contentWindow.print(), with no luck. I can't list all the variations I have tried but, I think I have tried them all. ugh. (for clarity, 'main' is nested in side framesets but no other frame so window.top.frames['main'] works even though main is nested several layers down). – rogdawg Mar 19 '14 at 20:34

1 Answers1

0

OK. The magic incantation is:

window.parent.frames[0].print();

This seems to work in IE and FF.

Interestingly, window.parent.frames['main'].print() does not work in IE.

OK. So, that's a day out of my life that I will never get back.

:-/

rogdawg
  • 687
  • 3
  • 11
  • 33