简体   繁体   English

具有iframe的页面可打印空白iframe

[英]page with iframes prints blank iframes

I have a page with iframes. 我有一个包含iframe的页面。 The iframes show in the browsers, but when I either print previerw or print in IE8, sometimes some or all of the frames are blank. iframe在浏览器中显示,但是当我打印previerw或在IE8中打印时,有时某些或所有框架都是空白的。 And by that I mean the frame and div is there but there is no content. 我的意思是框架和div在那,但没有内容。

The structure of the frame area is as follows: 框架区域的结构如下:

<div id="container">
    <div id="frames">
        <iframe src="about:blank" name="FRAME0"></frame>
    </div>
</div>

Forms have the iframes as targets. 表单将iframe作为目标。

Sometimes they print when using sheet size C, but the majority of the time they do not print. 有时他们在使用C尺寸的纸张时进行打印,但是大多数时候它们不打印。 Usually the first two iframes print and I have noticed that they are on the same page. 通常前两个iframe会打印,而我注意到它们位于同一页上。

The function I am using to print is: 我用来打印的功能是:

function printNow() {
    print();
}

I have tried focus() then print(), self.print(), window.print(), top.window.print(), etc. 我尝试过focus()然后print(),self.print(),window.print(),top.window.print()等。

Please tell me is this is an issue with IE8 or an issue that I can overcome with javascript. 请告诉我这是IE8的问题还是可以用javascript解决的问题。 I am forced to only use javascript. 我被迫只使用javascript。 Someone working on the project has a similar version for IE7 and they do not experience this problem less the iframe has a pdf file. 从事该项目的人员具有与IE7类似的版本,除非iframe具有pdf文件,否则他们不会遇到此问题。 There is css applied to iframe (ie, width: 100% ) and the iframes are can be conditionally hidden if a checkbox is selected using display:none . 如果将CSS应用于iframe(即width: 100% ),并且使用display:none选中复选框,则可以有条件地隐藏iframe。

You can use html2canvas to render iframes before print 您可以在打印前使用html2canvas渲染iframe

$('iframe').each(function() {
    var iframe = $(this);
    html2canvas(iframe[0].contentDocument.body, {
        onrendered: function(canvas) {
            var wrapper = iframe.hide().wrap('<div/>').parent().css({
                position: 'relative'
            });
            $(canvas).css('postion', 'absolute').appendTo(wrapper);
        },
        width: iframe.width(),
        height: iframe.height()
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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