【发布时间】:2023-03-06 20:30:01
【问题描述】:
我偶然发现了一个似乎是关于 iframes 的 Chrome 65 错误。
我无法使用 sn-p 来演示这一点,所以我使用了这个JSFiddle。
问题在于,如果iframe 是display: none;,则.print() 上的iframe 将不会打印任何内容。
它只发生在 Chrome 65 上,而不是 Chrome 64。
代码如下:
<iframe id="frame"></iframe>
<iframe id="frame2" class="hidden"></iframe>
<button class="db">Print without display: none;</button>
<button class="dn">Print with display: none;</button>
$('.db').on('click',function(){
$('#frame').contents().find('body').append('<p>Test without <code>display: none;</code>!</p>')
$('#frame')[0].contentWindow.print();
});
$('.dn').on('click',function(){
$('#frame2').contents().find('body').append('<p>Test with <code>display: none;</code>!</p>')
$('#frame2')[0].contentWindow.print();
});
.hidden{
display: none;
}
PS:不要尝试将其编辑为 sn-p,iframe 在其中不起作用。
【问题讨论】:
-
chromium.googlesource.com/chromium/src/+log/… — DisplayNoneIFrameCreatesNoLayoutObject 似乎相关。
-
@JoshLee 谢谢,但我必须说我不知道如何处理这些信息!
-
我假设您希望 display none iframe 在显式打印时打印?这在 Chrome 的 beta 版 (66) 上仍然存在问题,但它在金丝雀版 (67) 中有效,所以看起来这个问题将得到修复。
-
@Necreaux 很高兴知道这不仅仅是预期的行为,谢谢!
标签: javascript css google-chrome iframe