最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome 65 can't print hidden iframe - Stack Overflow

programmeradmin5浏览0评论

I stumbled upon what seems to be a Chrome 65 bug regarding iframes.

I can't use a snippet to demonstrate this, so I used this JSFiddle.

The problem is that if the iframe is display: none;, the .print() on said iframe won't print anything.

It only happens on Chrome 65, not Chrome 64.

Here is the code :

<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 : Don't try to edit this into a snippet, the iframes don't work inside them.

I stumbled upon what seems to be a Chrome 65 bug regarding iframes.

I can't use a snippet to demonstrate this, so I used this JSFiddle.

The problem is that if the iframe is display: none;, the .print() on said iframe won't print anything.

It only happens on Chrome 65, not Chrome 64.

Here is the code :

<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 : Don't try to edit this into a snippet, the iframes don't work inside them.

Share Improve this question edited Mar 15, 2018 at 15:41 Josh Lee 178k39 gold badges277 silver badges281 bronze badges asked Mar 14, 2018 at 15:05 ZenooZenoo 12.9k4 gold badges46 silver badges70 bronze badges 4
  • chromium.googlesource./chromium/src/+log/… — DisplayNoneIFrameCreatesNoLayoutObject seems relevant. – Josh Lee Commented Mar 14, 2018 at 18:07
  • @JoshLee Thanks, but I must say I have no idea what to do about this information ! – Zenoo Commented Mar 15, 2018 at 15:30
  • I'm assuming you expect the display none iframe to print when explicitly printed? This is still broken on the beta version of Chrome (66), but it works in the canary version (67), so it looks like this will be fixed. – Necreaux Commented Mar 23, 2018 at 14:13
  • @Necreaux Good to know it's not just expected behavior, thanks ! – Zenoo Commented Mar 23, 2018 at 14:14
Add a ment  | 

1 Answer 1

Reset to default 9

This may have been a deliberate change, but I don't know enough to say for sure. The change seems to have been https://crrev./526112 if you want to go exploring; there was some fallout from Google Docs so you're not alone in trying to work around this.

I can work around it by using

visibility: hidden;
position: absolute;

on the iframe to simulate the effect of display: none taking it out of the normal flow but still allowing it to perform its own layout. https://jsfiddle/28w1tomv/

发布评论

评论列表(0)

  1. 暂无评论