简体   繁体   中英

Can't find a cross-browser solution for printing from an iFrame

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.

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.

:-/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM