Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have some limitations when printing the contents of an IFrame. JavaScript security policies will prevent you from printing something if its in a different domain. This is the method I've used for years to print specific content on a page.</p> <p>First you need a simple print function in JavaScript. This is the one I use</p> <pre><code> print = function(str) { var WinPrint = window.open('', '', 'left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0'); WinPrint.document.open("text/html", "replace"); WinPrint.document.write('&lt;html&gt;&lt;head&gt;&lt;title&gt;Printing&lt;/title&gt;&lt;/head&gt;&lt;body&gt;'); WinPrint.document.write(str); WinPrint.document.write('&lt;/body&gt;&lt;/html&gt;'); WinPrint.document.close(); WinPrint.focus(); WinPrint.print(); WinPrint.close(); }; </code></pre> <p>Then you need to pull the HTML from the iframe </p> <pre><code> getIFrameContent = function(IFrameID) { return document.getElementById(IFrameID).contentWindow.document.body.innerHTML; }; </code></pre> <p>Then a simple function to wrap the whole thing to make it easier</p> <pre><code>printIFrame = function(IFrameID) { print(getIFrameContent(IFrameID)); }; </code></pre> <p>Once you have all that you can call the printIFrame method and simply send in the ID of the IFrame.</p> <p>Method 2: Open the Iframe in a new window and print that window.</p> <pre><code> var printIFrame2 = function (IFrameID) { var URL = document.getElementById(IFrameID).getAttribute("src"); var WinPrint = window.open(URL, 'WinPrint', 'left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0'); WinPrint.focus(); WinPrint.print(); WinPrint.close(); }; </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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