Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome 65 can't print hidden iframe

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.

like image 513
Zenoo Avatar asked Mar 14 '18 15:03

Zenoo


1 Answers

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.com/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.net/28w1tomv/

like image 168
Josh Lee Avatar answered Oct 15 '22 07:10

Josh Lee