1

How to print iframe inner content. In this iframe URL page also having one more iframe.

i have used this URL into my iframe.

<iframe width="700" height="500" src = "https://www.cashpayment.com/Public/PaymentCenterLocator?MerchantID=946">

I want to print this content.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
user2354274
  • 187
  • 5
  • 16

1 Answers1

0

Try this,

var mywindow = window.open('', 'iFrameTagId', 'height=500,width=500');
        mywindow.document.write('<html><head><title>title</title>');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);//iFrame data
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

Or you directly open this page and use below code while page load

$(document).ready(function () {
    window.print();
    setTimeout('window.close();', 100);
});

Updated Code

function iprint(ptarget) {

        var mywindow = window.open('', 'ptarget', 'height=500,width=500');
        mywindow.document.write('<html><head><title>title</title>');
        mywindow.document.write('</head><body >');
        mywindow.document.write($(ptarget).html()); //iFrame data
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();
    } 

<iframe name="theiframe" id="theiframe" width="700" height="500"  src = "http://localhost:54649/WebSite6/Default.aspx"></iframe> 
 <input type="button" class="btninput" value="print iframe" onclick="iprint('#theiframe');" /> 
Jeet Bhatt
  • 744
  • 1
  • 7
  • 22