Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print DIV in iframe

    My goal is to have a page with an iframe on it. The page in the iframe will have a div. I need a button or link on the main page that will print the contents of the div within the iframe. I know how to print the contents of an iframe from the main page using the code below. I also know how to print the contents of a div on the main page with the code below. I just don't know how to combine the two to print the div in the iframe. Thank you in advance to anyone who can help.

    Here is my code to print out the contents of iframe (I1):

    <script language=JavaScript>
    function CheckIsIE()
    {
    if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') { return true;}
    else { return false; }
    }

    function PrintThisPage()
    {

    if (CheckIsIE() == true)
    {
    document.I1.focus();
    document.I1.print();
    }
    else
    {
    window.frames['I1'].focus();
    window.frames['I1'].print();
    }
    }
    </script>

    And here is my code to print contents of a div on the same page as the button or link:

    <script language="JavaScript">
    var gAutoPrint = true; // Flag for whether or not to automatically call the print function

    function printSpecial(name)
    {
    var name
    if (document.getElementById != null)
    {
    var html = '<HTML>\n<HEAD>\n';

    if (document.getElementsByTagName != null)
    {
    var headTags = document.getElementsByTagName("head");
    if (headTags.length > 0)
    html += headTags[0].innerHTML;
    }

    html += '\n</HE' + 'AD>\n<BODY>\n';

    var printReadyElem = document.getElementById(name);

    if (printReadyElem != null)
    {
    html += printReadyElem.innerHTML;
    }
    else
    {
    alert("Could not find the printReady section in the HTML");
    return;
    }

    html += '\n</BO' + 'DY>\n</HT' + 'ML>';

    var printWin = window.open("",name);
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();
    if (gAutoPrint)
    printWin.print();
    }
    else
    {
    alert("Sorry, the print ready feature is only available in modern browsers.");
    }
    }
    </script>

  • #2
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tested in IE7

    Code:
    <head>
    <script type="text/javascript">
    function ClickHereToPrint(){
        try{ 
            var oIframe = document.getElementById('ifrmPrint');
            var oContent = document.getElementById('divToPrint').innerHTML;
            var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
            if (oDoc.document) oDoc = oDoc.document;
    		oDoc.write("<html><head><title>title</title>");
    		oDoc.write("</head><body onload='this.focus(); this.print();'>");
    		oDoc.write(oContent + "</body></html>");	    
    		oDoc.close(); 	    
        }
        catch(e){
    	    self.print();
        }
    }
    </script>
    </head>
    
    
    <body>
    
    <a onclick="ClickHereToPrint();">Print</a>
    
    	<iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>
    	<div id="divToPrint">
    		content
    	</div>
    </body>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •