Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint iframe in IE
    primarykey
    data
    text
    <p>I have a button that loads a report for print into an "invisible" iframe inside a div and prints that iframe; the user presses a button to print the report (contained on a different page) without changing pages or any visual disruption aside from the print dialog. It works in Chrome and Firefox but not IE. In IE the parent page is printed in full, and a tiny messed up iframe is inserted at the bottom of the page (where I'm loading the iframe).</p> <p>Here's the empty div without content, it's there so I have an ID tagged place to style and stick content with Javascript:</p> <pre><code>&lt;div id="printerDiv"&gt;&lt;/div&gt; </code></pre> <p>Here's the javascript function, onClick of my button this function fires and inserts my print page into an iframe inside printerDiv, after loading this page it prints:</p> <pre><code>function printPage(url) { var div = document.getElementById("printerDiv"); div.innerHTML = '&lt;iframe src="'+url+'" onload=this.contentWindow.print();&gt; &lt;/iframe&gt;'; } </code></pre> <p>Here's the CSS hiding the div. I'm using absolute positioning to shift it off the visible screen area. I used to use display:none, but Firefox was unable to print iframes styled that way:</p> <pre><code>#printerDiv{ position:absolute; left:-9999px; } </code></pre> <p>When I print in IE it prints the full page, and then at the bottom, where <code>#printerDiv</code> is, I get this little iframe: <img src="https://i.stack.imgur.com/oX002.png" alt="enter image description here"></p> <p>So the content's being loaded, but it's not printing just the iframe, and it's not hiding the iframe properly either. Any other content I insert into <code>#printerDiv</code> is hidden properly, only the iframe displays like that.</p> <p>I've tried all solutions in <a href="https://stackoverflow.com/questions/1261561/printing-a-hidden-iframe-in-ie">this question</a> in my Javascript function: using <code>self.prin</code>t, using <code>document.parentWindow.print</code>, changing the styles on the printerDiv to 0px height/width doesn't work either. </p> <p>I'm welcome to solutions that don't use iframes (IE seems to have massive issues with them) but I need this ability to load content not visible on screen and print it directly via a button.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload